D
Dennis Russo
A little new to perl (and maybe hashes). I have two seperate arrays
that are in order, and I would like to create a hash table to combine
the two (ie $hash{arrayOne[5]}=arrayTwo[5]). I'm not sure why the
following code does not work (it only prints two blannk lines):
%hash = ();
for($i=0; $i<10; $i++) {
$a[$i]=$i;
}
for($i=10; $i<20; $i++) {
$b[$i]=$i;
}
$i=0;
foreach (@a) {
$hash{$_}=$b[$i];
$i++;
}
print "$hash{$a[0]}\n";
print "$hash{$a[1]}\n";
I am expecting the following output:
10
11
Any thoughts or inputs would be greatly appreciated!!
Thanks,
dr
that are in order, and I would like to create a hash table to combine
the two (ie $hash{arrayOne[5]}=arrayTwo[5]). I'm not sure why the
following code does not work (it only prints two blannk lines):
%hash = ();
for($i=0; $i<10; $i++) {
$a[$i]=$i;
}
for($i=10; $i<20; $i++) {
$b[$i]=$i;
}
$i=0;
foreach (@a) {
$hash{$_}=$b[$i];
$i++;
}
print "$hash{$a[0]}\n";
print "$hash{$a[1]}\n";
I am expecting the following output:
10
11
Any thoughts or inputs would be greatly appreciated!!
Thanks,
dr