Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Please explain 'list' assignment.

by shenme (Priest)
on Nov 03, 2006 at 19:19 UTC ( #582147=note: print w/replies, xml ) Need Help??


in reply to Re: Please explain 'list' assignment.
in thread Please explain 'list' assignment.

The 'x' operator can act upon strings or upon lists. The use above, "Hello" x 3" created three concatenated copies of the string "Hello", thus "HelloHelloHello". What you wanted was "three copies of an item in list context", like so:
my ( $var1, $var2, $var3 ) = ("Hello") x 3;
The parentheses force the value into list context, the 'x' then makes three copies of that single value list, and you get ("Hello", "Hello", "Hello"), which is what OP wanted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582147]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-01-24 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?