Re: Modifing Text Files
- From: telemachus07@xxxxxxxxx (Telemachus Odysseos)
- Date: Sun, 28 Oct 2007 20:47:43 -0400
On 10/25/07, Chas. Owens <chas.owens@xxxxxxxxx> wrote:
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.
Doesn't that code empty out a file? That is, isn't there a key line
missing:
#!/usr/bin/perl -i
use strict;
use warnings;
while (<>) {
s/this/that/;
print;
}
I apologize if "print;" was so obvious that it didn't even need to be
mentioned, but to be honest, I tried it without that line and emptied a few
test files before I got it right.
- Follow-Ups:
- Re: Modifing Text Files
- From: Chas. Owens
- Re: Modifing Text Files
- References:
- Modifing Text Files
- From: Joseph L. Casale
- Re: Modifing Text Files
- From: Chas. Owens
- Modifing Text Files
- Prev by Date: Re: What are the best jobs in Perl
- Next by Date: Re: How to prevent split from returning blanks
- Previous by thread: Re: Modifing Text Files
- Next by thread: Re: Modifing Text Files
- Index(es):
Relevant Pages
|