Re: Readline using foreach and while
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Fri, 28 Mar 2008 03:57:05 +0000
Quoth "szr" <szrRE@xxxxxxxxxxxxxxx>:
Actually the behaviors of "for (@ary)" and "for (@ary, ())" do seem
consistant if you really think about it. The resulting list is what it
iterates over (from the first element, to what ever *count* is... in the
former case *count* come fro mthe array, and since the condition is
checked at the start of each iteration, if the array is added to, the
count is incremented.
In the latter case, a new list is created from contents of @ary + an
empty list, which gives you a new list, which contains the values of
@ary, but is a new seperate list, and thus is not effected by changes to
@ary because it has it's own copy of @ary's values.
OK, now explain to me why
my @ary = qw/a b c/;
print map { /c/ and push @ary, 'd'; $_ } @ary;
*doesn't* work like that :).
Ben
.
- Follow-Ups:
- Re: Readline using foreach and while
- From: szr
- Re: Readline using foreach and while
- From: szr
- Re: Readline using foreach and while
- References:
- Readline using foreach and while
- From: Saurabh Jain
- Re: Readline using foreach and while
- From: szr
- Re: Readline using foreach and while
- From: Peter J. Holzer
- Re: Readline using foreach and while
- From: szr
- Readline using foreach and while
- Prev by Date: Re: Matching many when valid line exists
- Next by Date: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.8 $)
- Previous by thread: Re: Readline using foreach and while
- Next by thread: Re: Readline using foreach and while
- Index(es):