Hi all,

        This don't looks like a bug to me.

        Why, may you ask?

        It's simple. 

        1..10 is a list constructor, so, by itself returns a list, then in

        for (1..10) { $_++ },

        $_ is a list element, and not a constant.

        on the other hand in 
        
        for (1,2,3,4,5,6,7,8,9,10) { $_++ }

        each of the elements are directly and they are not list elements, but 
constants.

        the equivalent to the first for cycle would be

        for (@{[1,2,3,4,5,6,7,8,9,10]}) { $_++ }

        that works JUST FINE!

        I don't think this is a bug, but just syntax. I only think this should be 
documented.

Merlin, The Mage.

On Monday 06 May 2002 11:35 pm, William R Ward wrote:
> Jarkko Hietaniemi writes:
> >On Mon, May 06, 2002 at 08:25:11PM -0700, William R Ward wrote:
>
> [...]  To reduce it even farther, one of
>
> >> these works and the other doesn't - try it and see:
> >>
> >> perl -e 'for (1..10) { $_++; }'
> >> perl -e 'for (1,2,3,4,5,6,7,8,9,10) { $_++; }'
> >>
> >> Is this a known bug?
> >
> >I think perlsyn has had this for a while:
> >
> >  If any element of LIST is an lvalue, you can modify it by modifying
> >  VAR inside the loop.  Conversely, if any element of LIST is NOT an
> >  lvalue, any attempt to modify that element will fail.  In other words,
> >  the C<foreach> loop index variable is an implicit alias for each item
> >  in the list that you're looping over.
> >
> >That the first one works (as in, "doesn't fail", what it *does*, I
> >don't know) is to be considered an accident since I do not see any
> >lvalues in either.
> >
> >But that's a post-5.8.0 issue from my perspective.
>
> It's something that should (IMNSHO) at least be documented as a known
> bug.

-- 
Merlin, The Mage
new camelot site: affiliates.camelot.co.pt - Directorio de affiliate programs

Reply via email to