Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Why does foo() evaluate in array context in "${\foo()}"?

by ikegami (Patriarch)
on Apr 23, 2009 at 06:25 UTC ( [id://759476]=note: print w/replies, xml ) Need Help??


in reply to Why does foo() evaluate in array context in "${\foo()}"?

\(LIST) is documented to return a list of references to each member of the LIST in some cases.

>perl -e"print qq{$_: $$_\n} for \( 'a', 'b', 'c' );" SCALAR(0x239b9c): a SCALAR(0x239c9c): b SCALAR(0x239cec): c >perl -e"print qq{$_: $$_\n} for \qw( a b c );" SCALAR(0x239b9c): a SCALAR(0x239c9c): b SCALAR(0x239cec): c >perl -e"@a = qw( a b c ); print qq{$_: $$_\n} for \(@a);" SCALAR(0x239bac): a SCALAR(0x239c5c): b SCALAR(0x239cac): c >perl -e"@a = qw( a b c ); print qq{$_: @$_\n} for \@a;" ARRAY(0x1829a04): a b c

Same goes for subs, apparently.

>perl -e"print qq{$_: $$_\n} for \sub { qw( a b c ) }->();" SCALAR(0x239c5c): a SCALAR(0x239cac): b SCALAR(0x239cbc): c

Update: Clarified some.

Update: This differs from x's behaviour

>perl -le"@a = 'a' x 5; print 0+@a" 1 >perl -le"@a = ('a') x 5; print 0+@a" 5 >perl -le"@a = qw( a ) x 5; print 0+@a" 5 >perl -le"@a = sub { qw( a ) }->() x 5; print 0+@a" 1

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-28 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found