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
while (condition) # or for loop
$value <op>= something;
$sum += $_ for @nums;
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:
$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...
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>
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
Want more info? How to link or
or How to display code and escape characters
are good places to start.