"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]

Reply via email to