MeowChow has asked for the wisdom of the Perl Monks concerning the following question:
Just kidding, actually I worship $_, but today, I seek wisdom for a conondrum which rattles my faith in this most holy, virtuous, and altogether nifty variable. If $_ is a global variable, how does $_ become quasi-lexically scoped:
How does $_ get its value reset from the last 'h' value of the inner loop back to the numeric values of the outer loop? I was under the impression that $_ (namely, $::_) was a global variable. So what's story? Thanks for enlightening me...my @l = (1,2,3,4); my @m = qw(a b c d e f g h); for (@l) { for (@m) { print " $_ " } print " : $_\n"; } outputs a b c d e f g h : 1 a b c d e f g h : 2 a b c d e f g h : 3 a b c d e f g h : 4
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $_ haters anonymou
by tilly (Archbishop) on Dec 11, 2000 at 14:18 UTC | |
Re: $_ haters anonymou
by repson (Chaplain) on Dec 11, 2000 at 14:21 UTC | |
by tilly (Archbishop) on Dec 11, 2000 at 14:51 UTC | |
by repson (Chaplain) on Dec 11, 2000 at 15:54 UTC | |
by tilly (Archbishop) on Dec 11, 2000 at 16:04 UTC | |
by dchetlin (Friar) on Dec 11, 2000 at 16:17 UTC | |
by Dominus (Parson) on Dec 14, 2000 at 09:19 UTC | |
by redcloud (Parson) on Dec 14, 2000 at 20:22 UTC | |
by Dominus (Parson) on Dec 14, 2000 at 22:27 UTC | |
| |
by chipmunk (Parson) on Dec 11, 2000 at 19:56 UTC | |
Re: $_ haters anonymou
by extremely (Priest) on Dec 11, 2000 at 15:59 UTC | |
Re: $_ haters anonymou
by thealienz1 (Pilgrim) on Dec 11, 2000 at 20:15 UTC |
Back to
Seekers of Perl Wisdom