Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

print has a quite complex signature. It must distinguish between print $this; and print TO_THIS;, for example. So it also can tell between print @empty; and print;.

push is quite simple. You can write your own sub that offers the exact same interface:

sub Push(\@@);

So what to push onto the array is simply a (flattened) list (of scalar values). So push can't tell the difference between push @a; and push @a, @empty;... unless its simple interface gets special-cased for this. I'm not surprised that such special-casing was not deemed worth allowing the questionable usage of an implied $_.

At some point, somebody did some extra work to add the warning you get. The code you want would be added at the same point, but it would have to synthesize code to push the current value of $_ onto the stack before the push opnode (or thereabouts). That is certainly more work than just emitting a warning.

But then you'd have to fight the backward-compatibility battle -- which, frankly, I would consider a rather silly battle since transforming something that is useless and emits a warning into something useful (but perhaps of dubious wisdom) seems quite reasonable regarding backward compat.

- tye        


In reply to Re: why does push not default to $_? (simple) by tye
in thread why does push not default to $_? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found