in reply to Suggestions for optimizing this code...

There's no optimization to be done as far as slurping and spewing the file. A few minor points about the rest of it:
If you don't want to lose the newlines when you split, make it
@test = split /(?=\n)/, $rec;
Look at join for turning the array back into a single string.

From the code you post, there's no reason to declare $rec a second time.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Suggestions for optimizing this code...
by NeilF (Sexton) on Jan 17, 2006 at 10:22 UTC
    Is there no way to not use $rec and instead to split the record up within the sysread itself? eg: Something akin to:-

    sysread(DF, split(/(?=\n)/,$[0]), -s DF);

    I'm sure that's jibberish, but you get the idea...

      No. sysread is there for when you want large chunks of data and need to read them unbuffered. Noone does that when they need to process data line-wise – well, unless they are forced to operate under cartoonishly arbitrary and nonsensical constraints like “minimise the number of syscalls.”

      Seriously, what your hoster is asking of you makes no sense at all.

      Makeshifts last the longest.

Re^2: Suggestions for optimizing this code...
by NeilF (Sexton) on Jan 17, 2006 at 16:42 UTC
    In tests (on Perl on XP) splitting on "(?=\n)" is far far slower than a regular split on just "\n"...