Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Null-stripping performance

by BrowserUk (Pope)
on Feb 26, 2007 at 18:17 UTC ( #602188=note: print w/replies, xml ) Need Help??

in reply to Null-stripping performance

Another thought that would probably be more efficient, if all your null padded fields are numeric.

Perl quite happily interprets strings that contain digits and leading or trailing spaces as numbers without requiring the spaces to be removed first. If you simply replace all the nulls with spaces in a single operation:

$str =~ tr[\0][ ];

From that point on you can just use substr:

sub fetchOne{ substr $str, $_[ 0 ] * 4, 4 }

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2021-05-11 23:51 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (123 votes). Check out past polls.