in reply to Function speeds: lc() vs. eq vs. =~

Firstly, none of your cases are the same. You could use:

if( $type =~ /^CR\Z/i ) # or if( $type =~ /^CR$/i ) # if you want to allow for ignoring trailing newlines
and you'd have to use: if(  $type eq 'cr'  ||  $type eq 'CR'  ||  $type eq 'Cr'  ||  $type eq 'cR'  )

I'd argue that the speed difference is of extremely little importance in this case.

Use whichever makes the most readable code. So that eliminates the second one in my book. I like the first one.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Function speeds: lc() vs. eq vs. =~
by Clownburner (Monk) on Apr 17, 2001 at 18:56 UTC
    Good point, but I guess I should have been more precise about my situation, you see the database will only ever be in two states, cr or CR and never Cr or cR. So while checking for the last two states is OK it's really not required and if you're going to give each option as separate it's not really required.

    But thanks! I never played with Benchmark before, now I have new perl toys to play with! :-)
    Signature void where prohibited by law.