in reply to Re: ... for (@_) x= 2; (scalar assignment)
in thread ... for (@_) x= 2;

I supposed that three of my codes looks equivalently (for me), so and output should be the same - e.g. warning + compilation error.
  • Comment on Re^2: ... for (@_) x= 2; (scalar assignment)

Replies are listed 'Best First'.
Re^3: ... for (@_) x= 2; (scalar assignment)
by LanX (Saint) on Dec 29, 2015 at 14:03 UTC
    the list assignment returns the length of the list in scalar context, so
    DB<114> $l = ( @a = qw/a b/ ) => 2

    So it's not the same code!

    The difference between your code and my example is that there is no explicit variable (like $l) used here, but somehow it's still possible to change it.

    Maybe it's a side effect of for ? I dunno.

    I'd prefer a Can't modify warning here too!

    But it's still a very peculiar construction, so I'm not surprised if this edge case wasn't covered.

    HTH!

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    update

    More insights:

    ... it's not the temporary scalar which is modified but the resulting list in brackets

    DB<121> print "$_\n" for ($a=666) x= 2 666 666 => "" DB<122> $a => 666

    According to the already cited documentation of "combined assignments" this shouldn't be possible, b/c its a list operation.

      I tried compare three of my codes and their outputs. 'x=' seems doing the same in all three cases - it asks '@_' to be a scalar.
        > I tried compare three of my codes

        sorry?

        > x= seems doing the same in all three cases - it asks @_ to be a scalar.

        which is correct and documented.

        Anyway it might be an implementation flow that you sometimes don't get a warning or compilation error, but not a very serious one.

        I don't see the point discussing it further, since you have plenty of possibilities to achieve your goal in a much saner way.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!