Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: RegExps, Prematch and Postmatch without efficiency penalty

by Not_a_Number (Prior)
on Sep 14, 2003 at 15:20 UTC ( [id://291402]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        'vanilla' => sub {
                if ($text =~ /gotcha/) {
                    $pre = $`;
    ...
                }
            },
        }
    
  2. or download this
        print "vanilla\n";
        print "prematch  :", $`, "\n";
        print "match     :", $&, "\n";
        print "postmatch :", $', "\n";
    
  3. or download this
    Benchmark: timing 500000 iterations of substr, unpack, vanilla...
    substr:  5 wallclock secs <snip> @ 106678.05/s
    unpack:  8 wallclock secs <snip> @ 54241.70/s
    vanilla: 0 wallclock secs <snip> @ 492125.98/s
    
  4. or download this
    my ($i, $j, $k);
    for ('a' .. 'z', 'A' .. 'Z') {
      $i++ if $text2 =~ /$_/;
    }
    $j++ if $text3 =~ /quux/;
    $k++ if $text4 =~ /H/;
    
  5. or download this
    substr: 25 wallclock secs ...
    unpack: 26 wallclock secs ...
    vanilla: 26 wallclock secs ...
    
  6. or download this
    use strict;
    use warnings;
    use Benchmark qw(timethese);
    ...
    sub substr_postmatch {
        substr( $_[0],  $+[0] )
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://291402]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found