Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Expressing myself

by Kickstart (Pilgrim)
on May 12, 2001 at 05:37 UTC ( [id://79894]=note: print w/replies, xml ) Need Help??


in reply to Expressing myself

Just this should work I think:

m/.*?\<(.*?)\>/; print $1;

Kickstart

Replies are listed 'Best First'.
Re: Re: Expressing myself
by Kanji (Parson) on May 12, 2001 at 05:59 UTC

    .*? is at least better than .*, but I prefer to be a little more explicit and would use something like <([^>]+)> instead.

    Something you also might want to watch out for is your use of $1 without verifying the match actually succeeded, leaving you with something you probably didn't expect.

        --k.


      Just out of curiosity, I benchmarked this.

      #!/usr/bin/perl -w use Benchmark; $email = '<silvers@op.net>'; Benchmark::cmpthese(100000000, { '.*' => sub { $email =~ m/.*?\<(.*?)\>/ }, '^>' => sub { $email =~ m/<([^>]+)>/ } } );

      Results:

      Benchmark: timing 100000000 iterations of .*, ^>... .*: 1437 wallclock secs (1432.85 usr + 0.06 sys = 1432.91 CPU +) @ 69788.05/s (n=100000000) ^>: 645 wallclock secs (645.23 usr + 0.06 sys = 645.29 CPU) @ + 154969.08/s (n=100000000) Rate .* ^> .* 69788/s -- -55% ^> 154969/s 122% --

      - FrankG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found