This works great with one exception... the two values in the sed need to be
passed into the script...

IE:
changedbsid.pl OLDSID NEWSID filename(s)

could be ran against 1 or more files at a time.

I havethis which works like a champ on a SINGLE file

#!/usr/bin/perl -w

$^I = ".bak";

if ( @ARGV != 3 ) {
        print "You must supply two command line options\n";
        print "The OLD TOEKN and the NEW TOEKN\n";
        print "\n IE: $0 _VALUTEST _QAP2\n";;
        exit (1);
}

$OLD = $ARGV[0];
$NEW = $ARGV[1];
$FILES = $ARGV[2];
@ARGV = glob $FILES;
while(<>) {
        s/\Q$OLD\E/$NEW/g;
        print;
}

my problem is with multiple files, I could axe the ARGV check above.. but
that wont get me anywhere I do not think...

-Ron

> -----Original Message-----
> From: Michael R. Wolf [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 09, 2002 11:50
> To: [EMAIL PROTECTED]
> Cc: Yacketta, Ronald
> Subject: Re: Inline file edit
> 
> 
> "Yacketta, Ronald" <[EMAIL PROTECTED]> writes:
> 
> > Would I be able to use this inline? That is within a perl
> > script itself?  If so, might you provide an example?
> 
> 
> If you wanted to make a stand-alone perl script of it, it
> would look something like this.
> 
> #! /usr/bin/perl -w
> $^I = ".bak";
> while(<>) {
>     s/_VALUETEST/_QAP2/g;
>     print;
> }
> 
> Other alternatives include
> #! /usr/bin/perl -w -i
> #! /usr/bin/perl -w -i .bak
> $^I = undef;
> 
> 
> From the command line or within a shell script, it would
> look like this.  (With appropriate cautious testing, as
> previously mentioned.)
> 
> #! /bin/ksh
> perl -p -i ".bak" -e s/_VALUETEST/_QAP2/g original.scr
> #or 
> perl -p -i        -e s/_VALUETEST/_QAP2/g original.scr
> 
> 
> The big issue here is that if you specify "inline" outside
> the Perl program (on the command line), it uses the
> -i[extension] flag.  If you do it inside the Perl program
> you must use the $^I special variable.
> 
> ================
> -p  Causes Perl to assume the following loop around your
>     script, which makes it iterate over filename arguments:
>     
>     LINE:
>     while (<>) {
>         ...     # your script goes here
>     } continue {
>         print;
> 
>     The lines are printed automatically. To suppress
>     printing, use the -n switch. If both are specified, the
>     -p switch overrides -n. BEGIN and END blocks may be used
>     to capture control before or after the implicit loop.
> ================
> -i[extension] Specifies that files processed by the <>
>               construct are to be edited in-place. Perl does
>               this by renaming the input file, opening the
>               output file by the original name, and
>               selecting that output file as the default for
>               print statements. The extension, if supplied,
>               is added to the name of the old file to make a
>               backup copy. If no extension is supplied, no
>               backup is made.
> ================ 
> -e commandline  May be used to enter one or more lines of
>                 script. If -e is used, Perl does not look
>                 for the name of a script in the argument
>                 list. Multiple -e commands may be given to
>                 build up a multiline script. (Make sure to
>                 use semicolons where you would in a normal
>                 program.)
> ================
> $^I
> $INPLACE_EDIT  The current value of the inplace-edit
>                extension. Use undef to disable inplace
>                editing
> ================
> 
> -- 
> Michael R. Wolf
>     All mammals learn by playing!
>         [EMAIL PROTECTED]
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to