in reply to Re^2: A better way than ||
in thread A better way than ||
In principle, that is the approach, but I’d execute it a little differently since we’re not writing Pascal:
my ( $digits, $letter ) = $input =~ m{ ^ (\d{7}) ([A-Z]) $ }x; if( not defined $digits ) { print "Invalid input: $input\n"; return; # or last, or exit, depending on what sort of block we're in } # rest of code such as split //, $digits follows here
That avoids imposing another level of indentation upon the code in the normal flow of execution, and it keeps the condition check and its error handling close together.
Makeshifts last the longest.
|
|---|