in reply to Re^5: why does push not default to $_? (simple)
in thread why does push not default to $_?
(Incidentally, this works for me, but is it guaranteed to do so? I seem to remember—but can't find—a discussion here a while back indicating that, while arguments are often evaluated left-to-right, they aren't guaranteed to be. Do we know that the shift will happen before we test the value of @_?)sub push (\@;@) { CORE::push ( @{+shift}, @_ ? @_ : $_ ) }
UPDATE: LanX points out an extremely good answer to “why not?”, namely, “Because it behaves like accessors that get/set based on whether they have/don't have an argument, and passing an empty list leads to surprises.”
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: why does push not default to $_? (simple)
by ikegami (Patriarch) on Dec 07, 2008 at 19:04 UTC | |
Re^7: why does push not default to $_? (simple)
by LanX (Saint) on Dec 07, 2008 at 19:45 UTC |