Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Wow, lots of very interesting arguments to both sides of the debate, but no-one appears to have made the point that:
my( $foo, $bar ) = @_;
...is not the same as...
my $foo = shift; my $bar = shift;
The latter approach modifies the parameter list, they are gone. In the former case, they stay around to haunt you, especially if someone else calls a &foo, and what's left of @_ gets passed along. Talk about effects at a distance. One alternative is to never call &foo, but foo() instead. The other alternative is to use the shift approach. (note to self: remember to adopt tye's approach to fetching parameters).

If the routine is small enough I use $_[0] (in which case what $_[0] should contain should be easy to infer from the sub's name). But not everything can be done with $_[0]. If you want to modify it you must fetch the parameter, viz:

sub x { $_[0] =~ s/foo/bar/; $_[0]; } print x('food'), "\n"; # does not work

print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Shift versus Sanity (shift is not like assignment from @_) by grinder
in thread Shift versus Sanity by tadman

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 lurking in the Monastery: (5)
As of 2024-04-19 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found