[EMAIL PROTECTED] wrote:
I'd like to apply a series of inline edits to a file in Perl.

With sed, I could use "sed -f commandfile inputfile" or in awk, "awk -
f commandfile inputfile", however, I could not find an equivalent in
Perl.

perl commandfile inputfile

I'd prefer not to use sed or awk as they do not support inline
editing directly.

The version of sed that I have supports -i[SUFFIX], --in-place[=SUFFIX].

In Perl, what would be the way to apply a series of multiple inline
edits in this form to an inputfile?

commandfile:
s/searchterm/replaceterm/
s/searchterm2/replaceterm2/
s/searchterm3/replaceterm3/

#!/usr/bin/perl
use warnings;
use strict;

$^I = '';
while ( <> ) {
    s/searchterm/replaceterm/;
    s/searchterm2/replaceterm2/;
    s/searchterm3/replaceterm3/;
    print;
    }

__END__

Then make the file executable:

chmod 0750 /path/to/commandfile

And then run it like this:

/path/to/commandfile inputfile




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to