Dear Monks
A quick question about the return value of //. I have a simple script as shown below. I expect the 2nd and 3rd print statements print "5" but the 2nd print actually prints "4" instead. Really appreciate that if any one can explain why the 2nd print statement prints "4". Thanks.
#!/usr/bin/perl use strict; use warnings; my $a=" 456 789 123 456 789 "; my $count; $count = $a =~ /\d+/g ; print "$count\n"; $count = () = $a =~ /\d+/g ; print "$count\n"; my @a = $a =~ /\d+/g ; $count = @a; print "$count\n";
Results:
1 4 5
In reply to The return value of m// by sophate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |