in reply to Exiting subroutine via next -- Again

Check for validity inside a sub.

my @problems; sub required { my ($val, $msg) = @_; if ($val) { return 1; } else { push @problems, $msg; return 0; } } for my $row (@$data) { my ($cusip, $isin, $sedol, $ticker) = @$row; required($cusip, "Missing cusip for $ticker") or next; required($isin, "Missing isin for $ticker") or next; required($sedol, "Missing sedol for $ticker") or next; }

Update: The condition was inverted. Fixed.

Replies are listed 'Best First'.
Re^2: Exiting subroutine via next -- Again
by BillyNg (Initiate) on Jul 13, 2011 at 21:00 UTC
    Simple and brilliant. I bow to thee monk.