[VPM] spliting lines using unpack

Darren Duncan darren at DarrenDuncan.net
Wed Dec 27 02:01:24 PST 2006


At 10:38 PM -0800 12/26/06, Jer A wrote:
>I hear rumors that unpack is faster than split.
>
>suppose I have a very large string, (very very large) that contains 
>"\r\n"'s eg- lines
>
>what code do i need to split lines into an array using unpack.
>
>thanks in advance for your help.

AFAIK, unpack/pack is expressly for fixed-size records, and won't 
work for variable-width records like delimited ones probably are.

Is this string the content of a disk file, or is it from somewhere else?

If a file, you should usually just set the file input record 
separator to "\r\n" instead, so you don't vastly increase the amount 
of RAM you use by first reading the whole file into a string and then 
splitting it.  And with very large data, using a lot more RAM has its 
own performance implications.

At 2:28 AM -0500 12/27/06, abez wrote:
>I don't want to be mean or anything but if you're using perl you shouldn't
>worry too much about performance.

That's a bad stereotype if there ever was one.  Many operations in 
Perl are actually very fast, depending on what they are, since 
practically all the work for such is done with C code; eg, 90% as 
fast as native; or they are "fast enough", and performance concerns 
are often based on relative terms anyway.  So it is perfectly fair to 
both use Perl and care about performance.

-- Darren Duncan


More information about the Victoria-pm mailing list