[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regex is killing me--IT WORKS!--now, WHY?
- Subject: Re: regex is killing me--IT WORKS!--now, WHY?
- From: John Porter <jdporter@MIN.NET>
- Date: Sat, 30 Sep 2000 17:06:31 -0400
- In-reply-to: <B5FB6AB6.1A6%johng@lsu.edu>; from johng@LSU.EDU on Sat, Sep 30, 2000 at 10:02:30AM -0500
- Reply-to: PERL4LIB -- Perl For Libraries <PERL4LIB@LISTSERV.RICE.EDU>
- Sender: PERL4LIB -- Perl For Libraries <PERL4LIB@LISTSERV.RICE.EDU>
John Guillory wrote:
> The following command line invocation of perl works:
>
> system qq(perl -p -i.bak -e 's#$old#$new#g' $_); # works!
>
> But this one (without the -p and -i) does not acutally write out the
> substitution change back to $_. When I do perl -h to look at the list of
> switches, the help is minimal. I know the -i does file backup manipulation,
> but does the -p acutally 'print' it back to $_?
Yes. I think you really need that -p. Not only does it print each line
back to the file, but, more importantly, it wraps your little one-line
program in an implicit while loop so that every line of the file is
processed.
I think you need to get a little more familiar with the online docs;
perldoc perlrun would tell you all this.
One other observation. It is very tempting to run an external
invocation of perl, in order to exploit -p and -i. However, in your
case, it might be better to try to implement the function in perl code
inside your program, because it will probably be simpler, if a bit more
verbose. It may also run faster.
--
John Porter
Jetzt schalten wir das Radio an. Aus dem Lautsprecher klingt es dann...