Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 exploiting the Monastery: (8)
As of 2014-12-25 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls