Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: writing to the top of a file

by broquaint (Abbot)
on May 20, 2004 at 02:57 UTC ( #354836=note: print w/ replies, xml ) Need Help??


in reply to writing to the top of a file

Due to the nature of the structure of files you can't write to the top of them. So a simple solution is to create a new file and overwrite the old file e.g

open( my $old, '<', 'current.log' ) or die "ack: $!"; open( my $new, '>', 'current.log.new' ) or die "ack: $!"; print {$newfh} $your_data_here; print {$newfh} $_ while <$old>; close $old; close $new; rename 'current.log.new', 'current.log';
HTH

_________
broquaint


Comment on Re: writing to the top of a file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-11-27 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (182 votes), past polls