Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Prepending header line to HUGE csv file

by choroba (Cardinal)
on Oct 30, 2015 at 14:59 UTC ( [id://1146500]=note: print w/replies, xml ) Need Help??


in reply to Prepending header line to HUGE csv file

Files grow at the end. You can't easily insert a line anywhere else. You might try playing with the buffer size to speed up the process, though:
$/ = \65535; # You can try different numbers here. print {$NEW} $header; print {$NEW} $_ while <$OLD>;

Update: it seems read is a bit faster on my system. YMMV.

print {$NEW} $_ while read $OLD, $_, 2 ** 30 - 1;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-24 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found