Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Re: Re: Re: Checking Perl script on server

by smalhotra (Scribe)
on Jul 30, 2003 at 16:28 UTC ( #279240=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Checking Perl script on server
in thread Checking Perl script on server

Couple of things:
1. if /matchdata/ has any capturing () than $name is pushed into @files for each ().
2. When you do @data = (<LDATA>) you read the entire file into memory. A better way to do this would be:
foreach (@files) { open(LDATA, "$_") || warn "File does not open: $!\n"; open(TMP, ">$_.tmp") || warn "File Write problem $_.tmp: $!\n"; while (<LDATA>) { s/OLD/NEW/gi; print TMP $_; } close(LDATA); close(TMP); rename("$_.tmp", "$_") or warn "Could not rename '$_.tmp' to '$_': + $!\n"; }
Another side advantage of this is that if, for some reason, your script dies half way through then you still have our old file rather than a half written new file. hth.

$will->code for @food or $$;

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Checking Perl script on server
by waswas-fng (Curate) on Jul 30, 2003 at 22:14 UTC
    Another side effect from the entire file slurp that you had done with the code is that perl will alloc enough memory to fit the whole file into memory, and because of the way most OSs handle releasing memory back to the system you will find that your memory usage just for that portion of code is >= the largets file you act on until your perl script stops executing. This may be an issue (depending on your OS) where the system will not realize what memory is being used activly and force other applications to swap out if your memory is constrained.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-11-29 04:48 GMT
Find Nodes?
    Voting Booth?