Please explain to me this apparently inconsistent behavior:
use strict;
my @a;
print "a" x 2;
@a = "a" x 2; print @a;
print ("a") x 2;
@a = ("a") x 2; print @a;
Shouldn't the latter print one 'a'?
Editing: Okay, so now it makes sense to me: “Binary x” is a repeat operator ... In the context of a list, if the left operand is enclosed in parentheses or is a list formed by qw / STRING /, it repeats the list " perlop
It's as clear as mud to me (binary x - why use the word binary? Is there a notation X?) But anyway: @a = ("a") x 2 # seems to be in the context of the list, since we have an array at the beginning - the array is not a list, but contains a list, so I think we probably have a list context (and not an array context, although they may be synonyms).
Suppose the "left operand" ("a"). (This is either this or @a). perlop does not say what the operand really is, the query perldoc.perl.org gives "No matches were found," and googling gives "In computer programming, the operand is the term used to describe any object that can be manipulated." Like for example an array.
, , , , " ". : ("a") x 2
: ("a")
("a") x 2, ("a") x 2 ("a") x 2. .
: print $a[1], "a" , " " , Perl ("a") x 2 ("a", "a"), @a=("a", "a")
print ("a") x 2 ("a", "a"). , print " " . , : (print ("a")) x 2
- , , @a = =, . .