perl5
perl5 copied to clipboard
[doc] Wrong variable name in example
Where
Right before the start of:
https://perldoc.perl.org/perlretut#Using-independent-subexpressions-to-prevent-backtracking
Description $count2 is referenced in the example, but only once:
$count{lc($_)}++ for split('', "supercalifragilisticexpialidocious");
printf "%3d '%s'\n", $count2{$_}, $_ for ( qw{ a e i o u } );
Since this is the 2nd example, I figured the first line would refer to $count2 or the 2nd would remain as $count.
The wording can be updated.
I benchmarked the 2 style of commands and actually split is about 20% (at least for me):
perl -Me -e '
n {
split => sub{
my %c;
$c{lc($_)}++ for split(
"",
"supercalifragilisticexpialidocious"
)
},
fail => sub {
my %c;
"supercalifragilisticexpialidocious" =~
/([aeiou])(?{ $c{$1}++; })(*FAIL)/i
}
}, 1000000
'
Rate fail split
fail 114679/s -- -17%
split 137741/s 20% --
running that fragment gives warnings with perl -w I'm sure that was not intended, right?
@poti1 - thanks for pointing out e - beastmode unleashed! - I agree - it does not seem that " (It's remarkable that an alternative solution using something like ... is considerably slower.)
$ perl -Me /tmp/FAIL.pl
Rate split fail
split 254972/s -- -3%
fail 262329/s 3% --