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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

You don't get a warning when undef is interpreted as the identity element of the operator. Or, in other words, when the following pattern isn't useless

my $value; while (condition) # or for loop { $value <op>= something; }
For example:
my $sum; $sum += $_ for @nums;
or
my $valid; while (<DATA>) { chomp; next if /INVALID/; $valid .= $_; }
And not setting the variable before the loop let's you tell if there were no valid lines at all, or if the only valid data was empty strings (or $sum will be undef rather than 0 if there are no numbers).

On the other hand you can use whatever values you want, this will never yield anything but 0:

my $product; $product *= $_ for @nums;
This can only be a mistake.

So this would tend towards "this a right thing to do", but I couldn't find the documentation either.

Edit: that was full of typos. I wrote "under" for "undef", "is" for "if" and "identify" for "identity". I hope I got them all...


In reply to Re: Some "combined assignment operators" are exempt from "uninitialized value" warning. Is it documented anywhere? by Eily
in thread Some "combined assignment operators" are exempt from "uninitialized value" warning. Is it documented anywhere? by vr

Title:
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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2019-02-23 12:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I use postfix dereferencing ...









      Results (119 votes). Check out past polls.

      Notices?