Home > Archive > PERL Miscellaneous > March 2005 > Question on perl script.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Question on perl script.
|
|
| Unix_Shell 2005-03-29, 3:58 pm |
| Hello Group,
I am very new to the perl language and don't know much about it. I had
a question & maybe someone can help me decipher/modify a script.
We have AIX 5.2 & the script (test.sh) contains the following perl
command:
/usr/bin/perl
-014pe's|^|"'$PAGE1FORM'".(/Page:\s+1\s/?"\n":"'$CONTFORMSFX'\n")|e'
Basically, two values are being passed to this script. Variable
PAGE1FORM will contain $1 (example: "m_inv01") and CONTFORMSFX will
contain $2 (example: "_09").
Basically, the script is invoked as follows:
../test.sh m_inv01 _09 < inrptfile > outrptfile
The perl command processes the inrptfile by substituting the first line
of page 1 with m_inv01 and substituting the first line from page 2
onwards with m_inv01_09 (concatenation of $1 & $2).
Question: How can I make it substitute something completely different
from page 2 onwards? So, if I run the script as follows:
../test.sh m_inv01 pg2form < inrptfile > outrptfile
I would like the perl command to substitute the first line of page 1
with m_inv01 (just like above); however I would like it to substitute
the first line from page 2 onwards with pg2form (i.e. with whatever I
pass as $2 and *not* a concatenation of $1 and $2).
Thanks for any help.
S
| |
| Joe Smith 2005-03-30, 8:57 pm |
| Unix_Shell wrote:
> /usr/bin/perl
> -014pe's|^|"'$PAGE1FORM'".(/Page:\s+1\s/?"\n":"'$CONTFORMSFX'\n")|e'
>
> the first line from page 2 onwards with pg2form (i.e. with whatever I
> pass as $2 and *not* a concatenation of $1 and $2).
/usr/bin/perl
-014pe's|^|(/Page:\s+1\s/?"'$PAGE1FORM'\n":"'$CONTFORMSFX'\n")|e'
I would recommend getting rid of test.sh and using a perl script
instead of a perl one-liner.
-Joe
| |
| Anno Siegel 2005-03-31, 8:56 am |
| Unix_Shell <sgtembe@hotmail.com> wrote in comp.lang.perl.misc:
> Hello Group,
>
> I am very new to the perl language and don't know much about it. I had
> a question & maybe someone can help me decipher/modify a script.
>
> We have AIX 5.2 & the script (test.sh) contains the following perl
> command:
>
> /usr/bin/perl
> -014pe's|^|"'$PAGE1FORM'".(/Page:\s+1\s/?"\n":"'$CONTFORMSFX'\n")|e'
That's a single perl command line, presumably embedded in a shell
script. Since you don't show the rest of the script, it's hard to
guess what is going on.
> Basically, two values are being passed to this script. Variable
> PAGE1FORM will contain $1 (example: "m_inv01") and CONTFORMSFX will
> contain $2 (example: "_09").
>
> Basically, the script is invoked as follows:
>
> ./test.sh m_inv01 _09 < inrptfile > outrptfile
>
> The perl command processes the inrptfile by substituting the first line
> of page 1 with m_inv01 and substituting the first line from page 2
> onwards with m_inv01_09 (concatenation of $1 & $2).
It does nothing of this sort. It doesn't substitute lines, it inserts
a new line in front of each form-feed-delimited record. If the record
contains the string "Page: 1 ", it inserts the concatenation of the
input variables, otherwise it only inserts the second variable.
> Question: How can I make it substitute something completely different
> from page 2 onwards? So, if I run the script as follows:
It should do that, provided appropriate input. Apparently your input
data doesn't conform to what the script assumes.
If you change the Perl code to
s|^|"'$PAGE1FORM'".($.==1?"\n":"'$CONTFORMSFX'\n")|e
it will base the notion of "first page" on the record count in $.
But most of all you should rewrite the script as a Perl script. Perl
command lines are for the command line. Perl scripts are best written
as Perl scripts, not shell scripts.
Anno
|
|
|
|
|