Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: \ Operator in referencing

by Gilimanjaro (Hermit)
on Aug 06, 2004 at 13:56 UTC ( [id://380542]=note: print w/replies, xml ) Need Help??


in reply to \ Operator in referencing

It has nothing to do with functions...

\() returns a list of references to the variables in the list, so in this case a list of three references to the scalars. (Think (\"one",\"two",\"three")). But you assign it to a scalar... (So it becomes the last entry the list, which is 'three')

Example 2's $ref2 is just a reference to @list, so it indeed will return ARRAY when you ask what is refers to...

And Example 3's \() will give you a list of references to what's in the parentheses. But @list in list context, gets it's list expanded, so it's a list of three scalars again and assigning it to a scalar will give you the last entry 'three' again, thus ref $ref3 still is 'SCALAR'.

use Data::Dumper; print Dumper($ref1), "\n"; print Dumper($ref2), "\n"; print Dumper($ref3), "\n";
Should clear things up...

Update
In case of the $n = qw(one two three) makes $n eq 'three' not being clear, refer to chapter 2.3.4 of Programming Perl... It boils down to the list 'knowing' that it's being used in scalar context, and thus evaluating to the value of the last element, just like in C.

An array is slightly different from a list; an array returns it's size when evaluated in scalar context. Only in example 2 do you make the list an array by assigning it to @list.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found