question about $list[1] x @list2

J

jialin

@list1 = qw/aa ab ac/;
@list2 = qw/1 2 3 4 5/;
print $list1[2] x @list2,"\n";

========
i know the output will be "acacacacac",
but what this x means in $list1[2] x @list2,

thanks,
Jialin
 
J

jialin

I found the answer from perlop

Binary "x" is the repetition operator. In scalar context or if
the
left operand is not enclosed in parentheses, it returns a string
con-
sisting of the left operand repeated the number of times
specified by
the right operand. In list context, if the left operand is
enclosed in
parentheses, it repeats the list. If the right operand is zero
or neg-
ative, it returns an empty string or an empty list, depending on
the
context.

print '-' x 80; # print row of dashes

print "\t" x ($tab/8), ' ' x ($tab%8); # tab over

@ones = (1) x 80; # a list of 80 1's
@ones = (5) x @ones; # set all elements to 5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top