What happens there is a clever trick of prototypes in Perl 5. It doesn't pass a variable by reference, but passes a reference to the variable that was an argument. There is a difference. It also sidesteps the fact that any aggregate object passed into a subroutine by the default call-by-value would otherwise be flattened to a list. This flattening by the default variable passing mechanism is evidence against calling Perl aggregates first-class objects.
If what happened was really "pass by reference" in a classical sense, one would be able to operate on the passed variable by the lexical or localized variable's name without regard for the reference, only it would effect the original. That's not what happens. You can force the subroutine, via the prototype mechanism, to take a reference to the argument but you still have to treat it as a reference.
sub foo (\@) {
print pop @{$_[0]};
};
@bar = qw( foo bar );
foo @bar;
BTW, lists are not precluded from being first-class simply by not being named, either, as JavaFan pointed out as a disqualification earlier. Anonymous lists, anonymous functions, and anonymous closures are first-class objects in some languages.
As I said before, what constitutes a first-class value can vary by language. In Perl, one could consider arrays and hashes as first-class, but one could make arguments against that classification as well.
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.