[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regex is killing me--IT WORKS!--now, WHY?



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...