Justin C <> writes:
> On 2012-04-03, Jim Gibson <> wrote:
[...]
>>> use List::Util qw(shuffle);
>>> my $str='1234567890!@#$
>>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJK LZXCVBNM_+{}|:"<>?~`-
>>> =[]\;\',./1234567890!@#$
>>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJK LZXCVBNM_+{}|:"<>?~`-
>>> =[]\;\',./';
>>
>> Here is a way to build up your source string from pieces that are
>> easier to type and understand:
>>
>> my $numbers = join('',(0..9));
>> my $letters = join('',('a'..'z'));
>> my $ucletters = uc $letters
>> my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
>> my $str = $numbers . $letters. $ucletters. $punct;
>> $str .= $str;
>
> Seeing as the OP, after constructing a string, then converts it into an
> array, why not skip straight to the array... at least with the easy
> bits:
>
> my @bits = (0..9, "a".."z", "A".."Z");
> my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
> push @bits, $_ for (split(//, $punct));
Including the result of this code as literal value in the source is a
better idea than regenerating it everytime the code runs. A way to do
this with an array (assumes ASCII and relies on ord('(') < ord(')')) would be:
----------
@chars = map { $c = chr($_); $c =~ /[[:graph:]]/ ? $c : (); } (0 .. 127);
print('my @chars = qw(', join(' ', @chars, @chars), ");\n");
----------
This will print Perl-code creating and initializing the array @chars
with a suitable set of values and this code can then be included
in the script. It is also a nice example of something useful which
can't be 'enhanced' by use warning; use strict

.