}
>$hash{$temp}->{'foo'} = 42;## now it works
>}
-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 1:14 PM
To: Bradford Ritchie
Cc: [EMAIL PROTECTED]
Subject: Re: foreach() index scoping question
On Feb 19, Bradford Ritchie said:
>foreach my $elem (@long_list) {
>my $k="junk";
>foreach $k (keys %hash) {
> last if($elem =~ /$k/);## ok, I've got the $k I need
>}
>$hash{$k}->{'foo'} = 42;## oops, $k is reset to "junk"
>}
That behavior is documented, yes.
P
Hi,
I want to use a foreach loop to iterate over a list but I want to be able to
retain the index variable when the loop ends (either at the end of the list
or by an early-exit "last" statement).
Given the following example code:
#!/usr/bin/perl -w
use strict;
my %hash = ( "one" => {},## T