in reply to variable like $_

There are potentially ways by doing really deep trickery, but why would you bother? Just use assigned variables for each loop.

foreach my $k1 (keys %var) { foreach my $k2 (keys %{$var{$k1}}) { print('$var{$k1}{$k2}=', $var{$k1}{$k2}, "\n"); } }

Replies are listed 'Best First'.
Re^2: variable like $_
by Marshall (Canon) on Feb 04, 2009 at 12:29 UTC
    I like this post and looks good to me! There is no penalty for having a lexical "my" variable as an iterator in a "foreach" loop. Think about it, here $k1 and $k2 are separate things. Even if you succeed in writing this with just $_, you haven't saved anything, Perl will essentially create these vars even if you haven't given them names - they are separate things to Perl (inner $_ is separate from outer $_). Give them names! I agree!