in reply to Re^2: Reference of constants and literals
in thread Reference of constants and literals
First of all, push is not a subroutine. I'll concentrate on your second example, sub name (\@@).
While it could be a matter of interpretation in general, it's unequivocal in this case because we're talking about the value of $_[0]. The \@ prototype causes a reference to the array to be passed to the sub, not an array. $_[0] contains a reference, not an array. Printing \$_[0] would print a reference to a reference to an array, not a reference to an array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reference of constants and literals
by LanX (Saint) on Nov 24, 2008 at 11:11 UTC | |
> Printing \$_[0] would print a reference to a reference to an array, not a reference to a reference. well the constant gets always at runtime a reallocated space, while the arrayref doesn't!!! here a code that makes it hopefully clearer. UPDATE: no it doesn't, passing a ref to a literal scalar works as wanted!!!
Cheers Rolf | [reply] [d/l] |
by ikegami (Patriarch) on Nov 24, 2008 at 11:30 UTC | |
This is off topic. I wanted to ignore the push example to avoid going off topic. push is a named operator, which Perl calls "built-in function" or just "function". There are number of differences between subroutines and functions. As for CORE::push, it's very special. It's both a subroutine and a function depending how it's used. \&CORE::push returns a code ref, so it acts as a subroutine. But CORE::push(...) results in a push operator, not a subroutine call.
You haven't shown that the array ref doesn't get reallocated. To do so, you'd have to show that the array doesn't happen to get reallocated at the same memory address. All you have is a theory. One that's provably false.
And that brings me back to my earlier answer. The behaviour is not intentional. It's a fluke and relying on it is dangerous. | [reply] [d/l] [select] |
by LanX (Saint) on Nov 24, 2008 at 16:34 UTC | |
OUTPUT Thanks for teh discussion!!! Cheers Rolf | [reply] [d/l] [select] |