[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-beginners
Subject: Re: Modifing Text Files
From: "Chas. Owens" <chas.owens () gmail ! com>
Date: 2007-10-29 10:53:44
Message-ID: 58ce48dc0710290353i6cffaf6cr2be90722a38a9e1 () mail ! gmail ! com
[Download RAW message or body]
On 10/28/07, Telemachus Odysseos <telemachus07@gmail.com> wrote:
> On 10/25/07, Chas. Owens <chas.owens@gmail.com> 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.
>
Doh!, that was supposed to be -pi on the command line version and a
print in the full code.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic