in reply to Validating ISBN numbers?
This doesn't return anything, but throws an exception for invalid values. You could use it like this:sub assert_valid_isbn { local($_) = @_; s/^ISBN\s*// or die "'$_' does not begin with 'ISBN'"; y/- 0-9//cd and die "'$_[0]' contains invalid characters"; /-/ && / / and die "'$_[0]' contains both hyphens and spaces"; y/-/ /; # convert hyphens to spaces. my @g = split; @g == 4 or die "'$_[0]' is broken into the wrong number of groups" +; join('',@g) == 10 or die "'$_[0]' contains the wrong number of dig +its."; }
for my $isbn ( @isbns ) { eval { assert_valid_isbn( $isbn ); process_this_isbn( $isbn ); }; $@ and warn $@; };
jdporter
...porque es dificil estar guapo y blanco.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(z) Re^2: CGI -Perl problem
by zigdon (Deacon) on Dec 17, 2002 at 18:01 UTC |