Herkum has asked for the wisdom of the Perl Monks concerning the following question:
I had to lc() the $var variable to for the key comparision. I started thinking, is there another way to do this? Well I could have done this,for my $var (@vars) { print "Value: " . $hash_ref->{lc $var} . "\n" if exists $hash_ref- +>{lc $var}; }
Then I started thinking, what if I wanted to do this except it was invalid Perl.for my $var (@vars) { my $new_var = lc $var; print "Value: " . $hash_ref->{$new_var} . "\n" if exists $hash_ref +->{$new_var}; }
NOW, I am thinking, how does a value get from @vars to my $var? If there is an internal iterator used by the for loop, does it put a value into the variable assignment or can you put an expression in there in some way? I admit I have never seen it before, but it is Perl!for my $var = lc $_ (@vars) { print "Value: " . $hash_ref->{$var} . "\n" if exists $hash_ref->{$ +var}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How a for() assignment works
by jwkrahn (Abbot) on Mar 06, 2008 at 21:24 UTC | |
by Herkum (Parson) on Mar 06, 2008 at 21:28 UTC | |
|
Re: How a for() assignment works
by NetWallah (Canon) on Mar 06, 2008 at 21:31 UTC | |
|
Re: How a for() assignment works
by amarquis (Curate) on Mar 06, 2008 at 21:32 UTC | |
by NetWallah (Canon) on Mar 06, 2008 at 21:36 UTC | |
by Argel (Prior) on Mar 07, 2008 at 20:27 UTC | |
by NetWallah (Canon) on Mar 08, 2008 at 01:09 UTC | |
by Argel (Prior) on Mar 08, 2008 at 01:42 UTC | |
|
Re: How a for() assignment works
by CountZero (Bishop) on Mar 07, 2008 at 07:07 UTC | |
by jwkrahn (Abbot) on Mar 07, 2008 at 13:24 UTC | |
|
Re: How a for() assignment works
by igelkott (Priest) on Mar 06, 2008 at 21:38 UTC | |
by ikegami (Patriarch) on Mar 07, 2008 at 06:01 UTC | |
by igelkott (Priest) on Mar 07, 2008 at 09:30 UTC | |
|
Re: How a for() assignment works
by repellent (Priest) on Mar 07, 2008 at 17:05 UTC | |
by jwkrahn (Abbot) on Mar 07, 2008 at 23:25 UTC |