Oh good monkies, I need thy wisdom. I'm doing a data integrity check on data I'm receiving from a DB (that I can't control) and if an integrity problem is found, I run a sub that takes care of a few things like printing to the stdOut log, creating an error message and throwing it into an array for later emailing to our team, AND (here's the big one) ... calling NEXT to jump out of the current foreach loop (I'm foreaching through each row of my dataset. Code looks something like this:
my @problems;
foreach my $row (@$data)
{
my ($cusip, $isin, $sedol, $ticker) = @$row;
&problem("Missing cusip for $ticker") unless ($cusip);
&problem("Missing isin for $ticker") unless ($isin);
&problem("Missing sedol for $ticker") unless ($sedol);
}
sub problem
{
my $issue = shift;
print "$issue\n";
push (@problems, $issue);
next;
}
Now, this code works correctly but throws the old "Exiting subroutine via next at <line>" junk to stdErr and I don't like that.
I know that I could pull the "next" out of the sub and write my if/unless like this:
if !($cusip)
{
&problem("Missing cusip for $ticker");
next;
}
But that's going to get ugly considering I've got about a dozen pieces of data to check and I hate using up 60 lines of code just to do the integrity checks.
Any ideas?
--Billy
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.