Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

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

It's action-at-a-distance in that given the statement my $foo = split( /;/, $bar ); you haven't mentioned @_ at all and yet @_ will be modified. I can see the case for an analogy with $_, but in the cases where $_ is used as a default argument (and @_ is used similarly only for push pop shift unshift that I can recall off hand) you don't specify any argument and $_ (or @_) is what's mucked with. In the example I give @_ is never mentioned but there is an explicit argument passed ($bar). That's what I mean by action-at-a-distance; I mentioned another variable explicitly and yet @_ is altered implicitly.

Again, I don't think it's really an error in general since it works fine save for this corner case. But I definitely wouldn't blink twice at a documentation patch adding an explicit warning about this corner case (again analogous to the warning against modifying the variable in a for loop in perlsyn). While the for case isn't destructive per se, the behavior is undefined for both and should be avoided because you can't depend on what it's going to do (just as you can't depend on what splitting in scalar context from an element of @_ is going to do). And on the third hand I also wouldn't think it worthless to maybe forward your test case on to p5p and see if anyone there thinks the bad behavior is worth looking deeper in.

I still think it's mostly a "Doctor! Doctor! It hurts when I do this!"/"Well, don't do that." situation. Don't exercise the corner case and there's no problems.

Update: minor edit and added note about running past p5p.

The cake is a lie.
The cake is a lie.
The cake is a lie.

In reply to Re^3: messing with @_ by Fletch
in thread messing with @_ by polettix

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others goofing around in the Monastery: (7)
    As of 2024-07-12 12:30 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.