Fellow Monks,
I recently ran into a seemingly simple problem, which to my complete surprise managed to stumped me.
Scenario:
for my $row (@{$dates}) {
$seasons{'low'} = $row->[0] if ($row->[0] < $seasons{'low'});
$seasons{'high'} = $row->[1] if ($row->[1] > $seasons{'high'});
}
At some point the vars
$row->[0] and
$row->[1] were empty, this eventually broke a few other parts of the code which depended on this information. What I was wanting to do is act on the variables if the $row vars were empty, rather than checking for a value I assumed I could act if $! had a value.
for my $row (@{$dates}) {
$seasons{'low'} = $row->[0] if ($row->[0] < $seasons{'low'});
print "$row->[2]\n" if $!;
$seasons{'high'} = $row->[1] if ($row->[1] > $seasons{'high'});
}
The theory behind it was that if an uninitialized var was being used a warning would pop up and I would print the corresponding id to let me know if it was empty.
I was trying to save myself a little bit of work by not testing the variable for a value. Of course my thoughts on how to do this were wrong since $! never had any value. I've scoured 'perldoc warnings & perlvar & perllexwarn ' to no avail, I am aware that I could use an eval to wrap the code in, but this is the innermost loop of a resource hungry piece of code and I was trying to avoid taking as many extra steps as possible to gain the advantage of speed.
Please note that this is not production code and the value of
$row->[2] obtained by testing would be used via another method to populate
$row
Any thoughts?
BlackJudas
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.