perlthirst has asked for the wisdom of the Perl Monks concerning the following question:
hi,
In the following code,use strict; use warnings; my %var = ( 'a' => { 'one' => '1', 'two' => '2', 'three' => '3', }, 'b' => { 'four' => '4', 'five' => '5', } ); foreach (keys %var ) { ## Here $_ will have a , b foreach (keys %{$var{$_}} ) { ## Here $_ will have one, two , + three, etc. print $_; ## With in this for loop, I wa +nt to access a and b. } }
How can i access $_ available in the first for loop, with in the inner for loop, with out using temporary variable to store $_ in the first for loop. How do i achieve this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: variable like $_
by fullermd (Vicar) on Feb 04, 2009 at 06:10 UTC | |
by Marshall (Canon) on Feb 04, 2009 at 12:29 UTC | |
|
Re: variable like $_
by targetsmart (Curate) on Feb 04, 2009 at 06:07 UTC | |
|
Re: variable like $_
by tilly (Archbishop) on Feb 04, 2009 at 06:13 UTC | |
|
Re: variable like $_
by ysth (Canon) on Feb 04, 2009 at 06:22 UTC | |
by Marshall (Canon) on Feb 04, 2009 at 12:42 UTC | |
by AnomalousMonk (Archbishop) on Feb 04, 2009 at 19:10 UTC | |
|
Re: variable like $_
by CountZero (Bishop) on Feb 04, 2009 at 06:11 UTC | |
by JavaFan (Canon) on Feb 04, 2009 at 10:06 UTC | |
by CountZero (Bishop) on Feb 07, 2009 at 14:47 UTC |