L
Louis.
Hi,
I am finding that outside the foreach loop my $i index does not exist
anymore, eventhough I defined it beforehand. This does not seem
logical. Is there a reason behind this?
Thank you in advance,
Louis.
my $i;
$url{1} = apple;
$url{2} = pear;
$url{3} = cherry;
$desc{1} = rose;
$desc{2} = tulip;
$desc{3} = sunflower;
foreach $i (keys %url) {
print "$i: $url{$i}\n";
if ( $url{$i} eq "pear" ) { $j = $i; print "found\n"; last; }
}
print "$i: $desc{$i}\n"; # nothing.
print "$j: $desc{$j}\n"; # works.
I am finding that outside the foreach loop my $i index does not exist
anymore, eventhough I defined it beforehand. This does not seem
logical. Is there a reason behind this?
Thank you in advance,
Louis.
my $i;
$url{1} = apple;
$url{2} = pear;
$url{3} = cherry;
$desc{1} = rose;
$desc{2} = tulip;
$desc{3} = sunflower;
foreach $i (keys %url) {
print "$i: $url{$i}\n";
if ( $url{$i} eq "pear" ) { $j = $i; print "found\n"; last; }
}
print "$i: $desc{$i}\n"; # nothing.
print "$j: $desc{$j}\n"; # works.