in reply to Null-stripping performance

You'd almost certainly be faster to unpack the entire string into an array once and then just index into the array:

my @numbers = unpack '(a4)*', $string;; ## Requires 5.8.x sub fetchOne { my $index = shift; return $numbers[ $index ]; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Null-stripping performance
by qiau (Initiate) on Feb 26, 2007 at 13:52 UTC
    Oh, forgot to say that the strings are pretty large so I don't think arrays would be the best solution.

    Each string is about 1 Mbyte that I read in from a file upon request so a standard use is to open about four files (sometimes more, sometimes less) and read values from different indexes in those strings.

    I think I tried with a array in the beginning but realized that splitting into 1 Mbyte arrays wasn't fast at all :).