in reply to Count number of occurrences of a substr
Well, you could use a useless assignment to (). Except it's not useless. As you've already demonstrated, a list assignment in scalar context returns the number of scalars returned by its RHS.
can be shortened to( my @a = `route print`=~ m!0.0.0.0!g ) > 3
and broken( () = `route print`=~ m!0.0.0.0!g ) > 3
should be changed to one ofmy $n = $str =~ m/this/g;
Some might prefermy $n = () = $str =~ m/this/g; my $n = grep 1, $str =~ m/this/g; my $n = map $_, $str =~ m/this/g;
my $n = 0; ++$n while $str =~ m/this/g;
|
|---|