I have tried for hours to solve this. Ok, the user enters a number, say 2020. 2020 is put into an array. {2, 0, 2, 0}. At
@array[0] = 2; 0 occurs twice in the string so this should print true; @array
1 1 occurs 0 times in the string so this should return true too. and
@array[2] 2 occurs 2 times in the string and this returns true; But when I enter 2020 , I get false true false true. I've looked at this for hours.
#!/usr/bin/perl -w
print "Enter number : ";
my $num = <STDIN>;
chomp($num);
@nums = split /(?<=[\d])/, $num;
$i = 0;
foreach (@nums)
{
if ($num =~ /[$i]{$_}/)
{ print "true"
} else {
print "false";
}
$i++;
}