in reply to Re: Unexpected value of $_ in a for loop.
in thread Unexpected value of $_ in a for loop.
(Firstly, thanks to the monks above for more efficient routines.)
The statement: push(@deck, splice(@_,$rand,1)); is what puzzles me (in my code).
After writing a sub:
my @arr = (5 .. 10); call_sub(@arr); sub call_sub { print "\n\n@_\n\n"; for (0 .. 4) { print "$_\t@_\n"; } print "\n\n"; }
I believe that $_ is a separate variable from @_ (and you can reference a scalar in @_ with $_[$sc]).
I had always assumed that $_ and @_ were connected, and that @_ referenced the elements in the for list as an array (which it doesn't).
It's a rather new discovery for me. Looking at how useful this is (rather than having to make temporary arrays in all your subroutines to carry parameters before going into a for loop), I see why it was done that way.
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected value of $_ in a for loop.
by jonadab (Parson) on Jan 16, 2004 at 20:55 UTC |