Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Write to filehandle without deleting current text

by k_manimuthu (Monk)
on Oct 05, 2010 at 12:48 UTC ( #863586=note: print w/replies, xml ) Need Help??


in reply to Re: Write to filehandle without deleting current text
in thread Write to filehandle without deleting current text

When the Read Mode file handler doesn’t to utilize another process you closed the file hander.

Then open the file a file handler in Write Mode with the same file name and print the contents you will the new (updated) contents in the sample file.

#!/usr/bin/perl $fileName = "abc"; open(IN, "<", "$fileName") or die "Could not open file $fileName"; read IN, my $new, -s IN, close (IN); $new =~ s/foo/bar/g; # Open the the file in write mode open(OUT, ">", "$fileName") or die "Could not open file $fileName"; # print the new contents print OUT $new; close (OUT);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863586]
help
Chatterbox?
[LanX]: suitable what? ... insult?
[Discipulus]: goodby stress..
LanX you always reminded me of Sean Connery. ..
shmem .oO( someday I'll do something... and then I'll make it big. Now is the time! )

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2018-04-24 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?