Re: Perl read in line to variable in script (148 Views)
Reply
Super Advisor
Ratzie
Posts: 852
Registered: ‎01-10-2002
Message 1 of 3 (148 Views)

Perl read in line to variable in script

I have a file with one entry on each line.
I want to read it into perl, and insert in a variable.

So the output will look like:
.BEGIN
UPDATE/2045555555,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR

.BEGIN
UPDATE/2045555555,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR

Yada, yada

#!/usr/bin/perl
use warnings;

open IN, "open OUT, ">out.txt";
open AC_OUT, ">AC_BULK_out.txt";
open ERR, ">err.txt";

print AC_OUT".LOG YES\n\n";

while() {
print OUT "$tn\n";
print AC_OUT <
UPDATE/$tn,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR

}

close IN, OUT, AC_OUT, ERR;
Super Advisor
Ratzie
Posts: 852
Registered: ‎01-10-2002
Message 2 of 3 (148 Views)

Re: Perl read in line to variable in script

Whoops forgot EOR in file, but I still cannot get it to work...
--------------------------

#!/usr/bin/perl
use warnings;

open IN, "open OUT, ">out.txt";
open AC_OUT, ">AC_BULK_out.txt";
open ERR, ">err.txt";

print AC_OUT".LOG YES\n\n";

while() {
print OUT "$tn\n";
print AC_OUT <
UPDATE/$tn,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR

EOF
}

close IN, OUT, AC_OUT, ERR;
Honored Contributor
Hein van den Heuvel
Posts: 6,588
Registered: ‎05-19-2003
Message 3 of 3 (148 Views)

Re: Perl read in line to variable in script

Ratzie,

------------------- tmp.pl -------
use warnings;
print ".LOG YES\n\n";
while(<>) {
chomp;
print <.BEGIN
UPDATE/$_,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR
EOF
}
------------------ tmp.tmp ----------
1234
5678
1231212312
--------- $ perl tmp.pl tmp.tmp -------
.BEGIN
UPDATE/1234,,,
.INSERT FEATURES
QUANTITY/1
FEATURE/VMP OCTEL
.END_INSERT
.EOR

.BEGIN
UPDATE/5678,,,
.INSERT FEATURES


--------------------------------------

Ratzie, if the above does not guide you towards a fix, then can you try that post again with a little more feeling?

What is the actual problem?

Do you really every expect the output to have two identical chunks as you show, or is that an unfortunate (lazy) example?

What does the input file look like?

What should the second output file look like? (just a log of numbers as read from input?)

Where does '$tn' come from?
transformed from $_ ?
How is $_ from while () ever used?

I like the << EOF usage for bulk text, but you do not show its FINAL usage... the EOF string itself

As you try to answer the above please consider doubling up the dat in a TEXT file to be attached such that no details get lost in formatting.

Finally... why/how is this an OpenVMS or HP question and no just a 'perl scripters beginners' forum question (assuming such beast exists)

Cheers,
Hein
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.