Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: why does push not default to $_?

by perreal (Monk)
on Dec 06, 2008 at 03:00 UTC ( [id://728474]=note: print w/replies, xml ) Need Help??


in reply to why does push not default to $_?

Well, I think print and push are different in that when you see:
print;
it feels like you want to print something, that thing being directly related to the context (default arg) makes sense. on the other hand:
push @a;
feels like we want to push @a to some place... like a stack. If there was a default stack than the right action would be to push @a to the default stack. So, I guess it is more about linguistics than implementation,

Replies are listed 'Best First'.
Re^2: why does push not default to $_?
by plobsing (Friar) on Dec 06, 2008 at 09:35 UTC

    There is a default stack. At least according to shift and pop.

    Making 1-arg push (and unshift) work with @_ (or @ARGV) as a default 1st arg would, IMHO, be more consistent (I have accidentally expected this behaviour once). Unfortunately, its not terribly useful. I don't find myself adding to @_ frequently.

      It's not a good idea. The only thing you could push onto the "stack" is would be the contents of an array. For example, you can't make push $foo; work without breaking push @foo, $x;. The usefulness of the feature is just too limited to compensate for the confusion the its implementation would cause.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://728474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found