in reply to Re^2: Lists and Arrays and Boredom
in thread Lists and Arrays and Boredom

Isn't the array evaluated in list context and the for loop iterated over a list?

No, it's optimized. You'll notice if you add elements to the array from within the loop, the loop will iterate over them too. That's wouldn't be possible if the array had been flattened to a list (as it is in the second program below) since changing the array would have no effect on the list.

>perl -le"@a=qw(a b); for (@a) { push @a, 'c' if /a/; print }" a b c >perl -le"@a=qw(a b); for (@a,()) { push @a, 'c' if /a/; print }" a b

The maintainers will be interested in your thoughts.

I might do that for "put in context" vs "evaluated in context". The rest of the comments don't apply to the FAQ. You made bad assumptions that if the FAQ mentions something about lists, it can't be the case for arrays as well (and vice-versa).

Replies are listed 'Best First'.
Re^4: Lists and Arrays and Boredom
by carol (Beadle) on May 17, 2008 at 21:59 UTC
    Thank you for your explanation.
    You made bad assumptions that if the FAQ mentions something about lists, it can't be the case for arrays as well (and vice-versa).
    I did not make such an assumption at all.
      For example, you assumed that a list can't be initialized with a list.