Home > Archive > PERL Miscellaneous > September 2006 > question about $list[1] x @list2
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
question about $list[1] x @list2
|
|
| jialin 2006-09-26, 9:59 pm |
| @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
| |
| jialin 2006-09-26, 9:59 pm |
| 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
jialin wrote:
> @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
| |
| Michele Dondi 2006-09-27, 4:00 am |
| On 26 Sep 2006 20:09:57 -0700, "jialin" <JialinLi1981@gmail.com>
wrote:
>i know the output will be "acacacacac",
>but what this x means in $list1[2] x @list2,
perldoc perlop
and search for 'Binary "x"'.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
|
|
|
|
|