In a message dated 4/17/2004 10:33:51 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:
>why was ^[^\.]+ suggested rather than ^.*?\. as a pattern.

I just Benchmarked it. qr(^.*?\.) is faster. 

#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
cmpthese(0, {
        '^[^\.]+' => sub {
            my $var = 'http://www.yahoo.com';
            $var =~ s/^[^\.]+//;
         },
        '^.*?\.' => sub {
            my $var = 'http://www.yahoo.com';
            $var =~ s/^.*?\.//;
        },
    }
);

Results:
            Rate ^[^\.]+  ^.*?\.
^[^\.]+ 665905/s      --    -25%
^.*?\.  891879/s     34%      --

I think ^[^\.]+ looks better. But that's just me :-)

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier
-DBD::SQLite

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to