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

Re: Suggestions for optimizing this code...

by Roy Johnson (Monsignor)
on Jan 16, 2006 at 22:19 UTC ( #523625=note: print w/replies, xml ) Need Help??

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"...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-06-25 04:35 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (81 votes). Check out past polls.