http://www.perlmonks.org?node_id=602188


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.