http://qs1969.pair.com?node_id=79320

footpad has asked for the wisdom of the Perl Monks concerning the following question:

The apprentice, after taking aspirin for the pain in his forehead, finally caves after several hours...

Some time ago, a certain monk (privately) advised the following after seeing my poor attempts to verify that a certain CGI parameter was actually a number, e.g. a non-blank, Base-10 numeric value that may (or may not) contain decimal points and/or hyphens masquerading as negative number indicators:

Best perlop check? Try this: eval {local $^W = 1; $num + 0}; # Now check $@

Okay. So I'm trying to suit the action to these words and am not having much success:

#!/usr/bin/perl -wT use strict; $|++; use CGI qw( :standard ); my $result = ''; my %params = param(); if ( my $error = cgi_error() ) { print header( -status => $error ); exit 0; } my $invalue = param( 'INVALUE' ); if ( defined $invalue ) { eval{ local $^W = 1; $invalue + 0 }; ### Is Number? (Line 19) if ( $@ ) { $result = "$invalue is *not* a Number; Details: $@" } else { $result = "$invalue appears to be a number."; } } else { $result = "Enter a value to test." } print header( "text/html" ), start_html('Test'), h1('Validation'), start_form(), p( $result ), p( "Please enter a number to test: ", textfield( 'INVALUE', '' ) + ), p, submit, end_form, hr,"\n"; print end_html; exit 1;

As the more experienced of you will recognize, this is resulting in values such as "20" as being recognized as a number. Sadly, so are "Shoe", "Fred" and other patently non-numeric values, by which (just to be perfectly clear to the most rententive) are *not* numeric in the locale, idiom, and operational parameters that I'm trying to communicate in.

My petitions are:

Yes, I am aware of the Cookbook and its examples; you'll note this monk had a different approach in mind. I'm trying to get it to work. A gentle nudge would be greatly appreciated.

Many thanks in advance...

--f