dimanche 3 mai 2020

How do I know if there is a number in my list?

My code looks like this:

#!/usr/bin/perl
$counter=0;
@list=<STDIN>;
chomp(@list);
if (@list==~ /^[+-]?\d+$/ )
{
$counter++;
}
print $counter;

So I write datas like: a b c d 1 2 And then it should print 2

beacuse of the 1,2

But it does not matter what datas i write into the list i get back 0. So what is the problem with my if?

Aucun commentaire:

Enregistrer un commentaire