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

my $month_num = index('JanFebMarAprMayJunJulAugSepOctNovDec', $month_str)/3;
Now we're talking.

Replies are listed 'Best First'.
Re: Re^4: Pulling by regex II
by BrowserUk (Patriarch) on Dec 14, 2002 at 20:19 UTC

    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.