On 10/25/07, Joseph L. Casale <[EMAIL PROTECTED]> wrote: > I need to make some edits on small (~30 lines) text files. From reading > perldoc and > recent posts, am I correct in understanding that the proper way is to read > the file in > through one handle and write it out through another? If that is the case, I > suppose > I need to write in some code then to write the file out to a temp file, then > either move > it over top or delete the old file and rename the new file? > > What is the accepted method in this scenario? snip
>From the sound of it what you want is in-place-editing: #!/usr/bin/perl -i use strict; use warnings; while (<>) { s/this/that/ } The code above will read in any number of files modifying "this" to "that" in each one. It isn't really editing the files in place (it renames the input file, opens a file with to old name, and selects it for output), but it might as well from your perspective. If you want a backup copy of the old file just add an extension after the -i like this #!/usr/bin/perl -i.bak You can also turn on in-place-editing by fiddling with the $^I variable. see perldoc perlrun and perldoc perlvar for more information. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/