in reply to Re: A better way than ||
in thread A better way than ||

it's an identification number of the shape 9525423E. @digits is gotten using a split:
I think in this case you're better of using a regex, so you can verify the input split more conveniently:
my $input = '9525429E'; if ( $input =~ /^([0-9]{7})([A-Z])$/ ) { my @digits = split //, $1; print "@digits, $2"; } else { print "invalid input"; }


holli, /regexed monk/

Replies are listed 'Best First'.
Re^3: A better way than ||
by Aristotle (Chancellor) on Jan 01, 2006 at 15:38 UTC

    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.