in reply to value returned on m// failure
The "undefined value" does test false?
sub if_integer{ return defined $_[0] && $_[0] =~ m/^\d+$/; } if_integer($_) and print $_, ' is an integer', $/ for -1, 0, 1, 2, 2.2, 1E0, '1E2', 'A', '123', '123 fred' 0 is an integer 1 is an integer 2 is an integer 1 is an integer 123 is an integer
So the logic of the test works fine.
Of course your regex is a little primitive as it excludes all negative integers, as well as those represent in exponential form, '1E0' for example.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: value returned on m// failure
by parv (Parson) on Dec 31, 2002 at 01:40 UTC |