Help for this page

Select Code to Download


  1. or download this
    expr      := number
               | expr ws unary_operator 
    ...
    ws        := ' ' | '\t' | '\r' | '\n'
    
    Note: I use "chs" as shorthand for 'c' 'h' 's'
    
  2. or download this
    digit  -> /(?<digit> \d )/msx
    number -> /(?<number> (?&digit)+ (?:[.](?&digit)*)
                    |     [.](?&digit)+ )/msx
    
  3. or download this
    qr{
    (?(DEFINE)
    ...
    )
        \A \s* (?&expr) \s* \z
    }msx;
    
  4. or download this
    String found where operator expected at (re_eval 10) line 1, near "say
    + "matching at ""
        (Do you need to predeclare say?)
    syntax error at (re_eval 10) line 1, near "say "matching at ""
    Compilation failed in regexp at rpg.pl line 137.
    
  5. or download this
    (?(DEFINE)
        (?<expr>
    ...
        \A \s* (?&expr) \s* \z
        (?(?{ $^R != 1 }) (*FAIL) ) 
    }msx
    
  6. or download this
      /(?<NAME>(?&NAME_PAT))(?<ADDR>(?&ADDRESS_PAT))
          (?(DEFINE)
              (?<NAME_PAT>....)
              (?<ADRESS_PAT>....)
          )/x
    
  7. or download this
        (?<number>
            ( (?> \d+ (?: [.] \d* )? | [.] \d+ ) )
            (?{ local @stack = ( @stack, $^N ) })
        )
    
  8. or download this
    qr{
    (?(DEFINE)
    ...
        (?{ $result = undef }) (*FAIL)
    
    }msx
    
  9. or download this
    qr{
        (?{ @stack  = ();
    ...
        (?(?{ @stack != 1 }) (*FAIL) )
        (?{ $result = $stack[0] })
    }msx,
    
  10. or download this
    my $input = join ' ', (1) x 1_001, ('+') x 1_000;
    
    ...
                s/iter recursive      flat
    recursive     1.35        --      -99%
    iterative 1.47e-02     9103%        --
    
  11. or download this
    # my $input = join ' ', 1, ('1 +') x 1_000;
                Rate recursive iterative
    recursive 40.5/s        --      -40%
    iterative 67.6/s       67%        --
    
  12. or download this
    # my $input = join ' ', (1) x 4, ('+') x 3;
                 Rate recursive iterative
    recursive 14306/s        --      -17%
    iterative 17271/s       21%        --
    
  13. or download this
    qr{
        \A \s*
    ...
        \s* \z
        (?(?{ $^R != 1 }) (*FAIL) )
    }msx,
    
  14. or download this
    # my $input = join ' ', (1) x 1_001, ('+') x 1_000;
                Rate recursive iterative
    ...
                 Rate recursive iterative
    recursive 28249/s        --      -69%
    iterative 92593/s      228%        --
    
  15. or download this
    #!//net/perl/5.10.0/bin/perl
    use warnings;
    ...
            say "FAILED: $line got $result, expected $input{$line}";
        }
    }