in reply to How can I test for the representation of an integer?
#!/usr/bin/perl use strict; use warnings; use Scalar::Util qw(looks_like_number); my @list = qw(1 "1" "1o"); foreach my $foo (@list) { if( looks_like_number( $foo ) ) { print "number\n"; }else{ print "string\n"; } }
Just use looks_like_number from Scalar::Util
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I test for the representation of an integer?
by BrowserUk (Patriarch) on Apr 25, 2016 at 13:31 UTC |