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

LanX cited: "> In list context, if the left operand is enclosed in parentheses or is a list formed by qw/STRING/, it repeats the list."

Now I tried to write some lines with 'qw' and found next interesting situation, which I can't understand:
#!/usr/bin/perl use warnings; use strict; $\ = $/; $, = '+'; print qw/a b/ x 2; print scalar(qw/a b/ x 2); print for (qw/a b/ x 2) x 2; print for qw/a b/ x 2 x 2;
OUTPUTS:
a+b+a+b
bb
a b a b a b a b
bbbb
The strange for me is the output of second 'print' (of course so does 4th too): it prints "bb" instead of supposed "b". I don't catch that, because print scalar('a','b','a','b'); would print "b".

Replies are listed 'Best First'.
Re^3: ... for (@_) x= 2; (scalar assignment)
by LanX (Saint) on Dec 29, 2015 at 14:32 UTC
    the documentation says that x can only act like a list repeater in list context.

    > > In list context, if the left operand is enclosed in parentheses or is a list formed by qw/STRING/, it repeats the list.

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

      Thanks :) . Now I catched it!
        It's one of these DWIM edge case implementations which make Perl less orthogonal. :-/

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