BillyNg has asked for the wisdom of the Perl Monks concerning the following question:
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:
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? --Billyif !($cusip) { &problem("Missing cusip for $ticker"); next; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exiting subroutine via next -- Again
by ikegami (Patriarch) on Jul 13, 2011 at 20:56 UTC | |
by BillyNg (Initiate) on Jul 13, 2011 at 21:00 UTC | |
|
Re: Exiting subroutine via next -- Again
by davido (Cardinal) on Jul 13, 2011 at 21:27 UTC | |
|
Re: Exiting subroutine via next -- Again
by choroba (Cardinal) on Jul 14, 2011 at 08:28 UTC | |
|
Re: Exiting subroutine via next -- Again
by JavaFan (Canon) on Jul 14, 2011 at 09:07 UTC |