Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: Pulling by regex II

by BrowserUk (Pope)
on Dec 14, 2002 at 08:12 UTC ( #219840=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Pulling by regex II
in thread Pulling by regex II

Why use an array and map and a hash. A string and index will do it.

my $month_num = index( 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov De +c', $month_str)/4;

Examine what is said, not who speaks.


Comment on Re: Re: Re: Pulling by regex II
Download Code
Re: Re: Re: Re: Pulling by regex II
by JayBonci (Curate) on Dec 14, 2002 at 08:25 UTC
    I'd want to get a hash out because of efficiency and grace if I were to call it multiple times. I wouldn't want to slug around that entire index function call invokation every time I wanted to lookup a month_name to month_num transform.

        --jb

      I was talking crap! :(


      Examine what is said, not who speaks.

Re^4: Pulling by regex II
by tadman (Prior) on Dec 14, 2002 at 20:10 UTC
    my $month_num = index('JanFebMarAprMayJunJulAugSepOctNovDec', $month_str)/3;
    Now we're talking.

      use constant MONTHS => 'JanFebMarAprMayJunJulAugSepOctNovDec'; ... my $month_num = index(MONTHS, $month_str)/3;

      Better still?

      Unfortunately, this (against my expectations) turns out to be between 30% & 50% slower than the hash solution.

      It uses much less momory, but it seems that hashing a 3 char string, indexing and returning the value is faster than a linear search for a 3 char string + a division.

      Surprised me


      Examine what is said, not who speaks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-26 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls