note
Marshall
I think that Version (2) and (1) do exactly the same thing.<br>
Version 2 is easier to understand. And I think that it is as least as fast if not faster. If we are benchmarking things, then we need to to "apples to apples".
<c>
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
## version 1....
my $num =0;
my %h = map{$_, $num++}('A'..'Z','a'..'z');
print Dumper \%h;
## version 2...
my %hash;
foreach my $letter (('A'..'Z','a'..'z'))
{
$hash{$letter}++;
}
print Dumper \%hash;
foreach (sort keys %h)
{
print "$_ OK\n" if $hash{$_};
}
</c>
<readmore>
<c>
$VAR1 = {
'S' => 18,
'a' => 26,
'T' => 19,
'N' => 13,
'K' => 10,
'd' => 29,
'Y' => 24,
'E' => 4,
'j' => 35,
'y' => 50,
'Z' => 25,
'u' => 46,
'k' => 36,
'g' => 32,
't' => 45,
'e' => 30,
'J' => 9,
'W' => 22,
'v' => 47,
's' => 44,
'B' => 1,
'H' => 7,
'c' => 28,
'q' => 42,
'b' => 27,
'D' => 3,
'I' => 8,
'G' => 6,
'z' => 51,
'U' => 20,
'w' => 48,
'F' => 5,
'r' => 43,
'x' => 49,
'V' => 21,
'Q' => 16,
'h' => 33,
'M' => 12,
'C' => 2,
'L' => 11,
'f' => 31,
'i' => 34,
'A' => 0,
'n' => 39,
'O' => 14,
'X' => 23,
'P' => 15,
'm' => 38,
'l' => 37,
'p' => 41,
'R' => 17,
'o' => 40
};
$VAR1 = {
'S' => 18,
'a' => 26,
'T' => 19,
'N' => 13,
'K' => 10,
'd' => 29,
'Y' => 24,
'E' => 4,
'j' => 35,
'y' => 50,
'Z' => 25,
'u' => 46,
'k' => 36,
'g' => 32,
't' => 45,
'e' => 30,
'J' => 9,
'W' => 22,
'v' => 47,
's' => 44,
'B' => 1,
'H' => 7,
'c' => 28,
'q' => 42,
'b' => 27,
'D' => 3,
'I' => 8,
'G' => 6,
'z' => 51,
'U' => 20,
'w' => 48,
'F' => 5,
'r' => 43,
'x' => 49,
'V' => 21,
'Q' => 16,
'h' => 33,
'M' => 12,
'C' => 2,
'L' => 11,
'f' => 31,
'i' => 34,
'A' => 0,
'n' => 39,
'O' => 14,
'X' => 23,
'P' => 15,
'm' => 38,
'l' => 37,
'p' => 41,
'R' => 17,
'o' => 40
};
A OK
B OK
C OK
D OK
E OK
F OK
G OK
H OK
I OK
J OK
K OK
L OK
M OK
N OK
O OK
P OK
Q OK
R OK
S OK
T OK
U OK
V OK
W OK
X OK
Y OK
Z OK
a OK
b OK
c OK
d OK
e OK
f OK
g OK
h OK
i OK
j OK
k OK
l OK
m OK
n OK
o OK
p OK
q OK
r OK
s OK
t OK
u OK
v OK
w OK
x OK
y OK
z OK
Process completed successfully
</c>
</readmore>
997326
997326