Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Modify file without any temp variable

by Llew_Llaw_Gyffes (Scribe)
on Jul 20, 2005 at 20:23 UTC ( [id://476607]=note: print w/replies, xml ) Need Help??


in reply to Modify file without any temp variable

Here's another approach:

my @orig = ($/, $\); undef($/); undef($\); open (JE, $file) || die "Cannot open $file"; (my $j = <JE>) =~ s/orig/new/g;

At this point you can either:

close (JE); open (JE, "> $file); print JE $j; close (JE); ($/, $\) = @orig;

or, more efficiently:

seek (JE, 0, 0); print JE $j; close (JE); ($/, $\) = @orig;

Log In?
Username:
Password:

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

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

    No recent polls found