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