I have array which values are user input like:
aa df rrr5 4323 54 hjy 10 gj @fgf %d
Now I want to check each value in array to see whether it's numeric, alphabetic (a-zA-Z), or alphanumeric and save them in other respective arrays.
I have done:
my @num;
my @char;
my @alphanum;
my $str =<>;
my @temp = split(" ",$str);
foreach (@temp)
{
print "input : $_ \n";
if ($_ =~/^(\d+\.?\d*|\.\d+)$/)
{
push(@num,$_);
}
}
This works. Similarly I want to check for alphabet, and alphanumeric values
Alphanumeric example are: fr43 6t$ $eed5 *jh
Perl supports POSIX character classes, so you can actually do this:
$string =~ /^[[:alpha:]]+$/;
$string =~ /^[[:alnum:]]+$/;
Numbers are less well defined, but Scalar::Util's looks_like_number function may do what you want it to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With