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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.