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. |