perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

[doc] Wrong variable name in example

Open poti1 opened this issue 1 year ago • 3 comments

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.

poti1 avatar Jun 08 '24 14:06 poti1

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%    --

poti1 avatar Jun 08 '24 14:06 poti1

running that fragment gives warnings with perl -w I'm sure that was not intended, right?

d-c-d avatar Jun 08 '24 15:06 d-c-d

@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%    --


d-c-d avatar Jun 08 '24 16:06 d-c-d