Operating System - OpenVMS
1752739 Members
5709 Online
108789 Solutions
New Discussion юеВ

Perl read in line to variable in script

 
Ratzie
Super Advisor

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;
2 REPLIES 2
Ratzie
Super Advisor

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;
Hein van den Heuvel
Honored Contributor

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