On Wed, 7 Jan 2015 07:56:18 +0000
Andrew Solomon <and...@geekuni.com> wrote:

> Hi Luca,
> 
> I haven't tested it, but my suspicion is that your first solution will
> be faster because regular expressions (which don't contain variables)
> are only compiled once, while you have a function call for every use
> of lc.
> 
> By the way another alternative might be:
> 
> $extention =~ /\.bat/i
> 
> (which would also match BaT, BAt...)
> 

The second code excerpt that was given will also match all that:

«
$extension = lc $extension;
$extension =~ / \.bat /x;
»

Anyway, one can use the Benchmark.pm module to determine which alternative is
faster, but I suspect their speeds are not going to be that much different. See:

http://perl-begin.org/topics/optimising-and-profiling/

(Note: perl-begin.org is a site I originated and maintain).

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Perl Humour - http://perl-begin.org/humour/

John: Hey, we are completely non-violent vampires. We don’t suck blood.
Selina: I thought all vampires suck blood.
John: Bullocks, hen. Vampires come in all shapes and sizes.
    — http://www.shlomifish.org/humour/Selina-Mandrake/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to