in reply to using int and the range function

You can check that using regexp:
if ($numind !~ /^\d+/) { ... }
Update: regexp is anchored to the beginning of the string.

Replies are listed 'Best First'.
Re^2: using int and the range function
by AnomalousMonk (Archbishop) on Jan 15, 2015 at 21:43 UTC
    c:\@Work\Perl>perl -wMstrict -le "my $numind = '345xy'; if ($numind !~ /^\d+/) { die qq{'$numind' is not a number}; } print 'sum is ', 123 + $numind; " Argument "345xy" isn't numeric in addition (+) at -e line 1. sum is 468

    Give a man a fish:  <%-(-(-(-<

Re^2: using int and the range function
by RonW (Parson) on Jan 16, 2015 at 01:17 UTC

    Also need to make sure there is nothing after the digits:

    while (<>) { chomp; if (/^\d+$/) { print "$_ is an integer\n"; } }
      We would also take into account sign or '0x' prefix for hexadecimal numbers. This way we will end up reimplementing Scalar::Util::looks_like_number() what AnomalousMonk suggested below.