Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Write contents of a file, whilst reading from another file

by dga (Hermit)
on Apr 01, 2003 at 16:00 UTC ( [id://247269]=note: print w/replies, xml ) Need Help??


in reply to Write contents of a file, whilst reading from another file

One way is to open 2 filehandles thus:

use strict; open(my $reader, '<', 'file.to.read'); open(my $writer, '>', 'file.to.write); # will be truncated while(<$reader>) { # do desired mangling here print $writer "$_"; }

This will copy file.to.read into file.to.write unchanged.

If you do stuff in the while where the comment is before writing then print the variable you want into the new file you have a filter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found