[oak perl] Perl for physical security :-)
Belden Lyman
blyman at iii.com
Wed Dec 4 18:18:53 CST 2002
David Alban wrote:
> At 2002/12/04/15:49 -0800 David Alban <extasia at mindspring.com> wrote:
>
>>my $codes = [ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
>> 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
>> 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
>> 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
>> 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
>> 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
>> 118, 119, 120, 121, 122, 123, 124, 125, 126 ];
>>
>
> Heh heh. This would be much more readable as:
>
> my $codes = [ 33..126 ];
>
> Doh!
And a tad more efficient as:
my $codes = [ map { chr $_ } 33..126 ];
Later, you can eliminate your call to chr(). This
way you just comput the chr of each @$codes member
just once, rather than each time you print it.
Incidentally, why use an array ref?
print $codes[ int rand @codes ];
vs
print $$codes[ int rand @$codes ];
Belden
More information about the Oakland
mailing list