MinniePerl
Technical User
I'm bringing data in from a:\, substituting x for s and counting the number of substitutions. Then I need to print the results out in a report. I can't get the Header(format REPORT_TOP=) to print out at all. I'm not sure what I'm missing. Also, the body prints out mostly zeros. Anybody see my blunders? Thx.
open (OLDFILE, "<a:\\program1.txt" #retrieve data
@databack=<OLDFILE>; #assigns to array
close(OLDFILE); #closes
foreach (@databack)
{ #creates foreach loop, so each array is split
#and subs are made, subs counted
$count=s/s/x/ig; #saves number of subs to $count
$total=$total + $count; #adds new sub. number to each loop
s/s/x/ig; #subs all s with x
($item, $itemprice, $itemnumber, $totalprice)=split(/, /,); #splits data
}
print "$total "."characters have been substituted.\n\n";
print @databack;
format REPORT_TOP=
========================================================== @<
ITEM PRICE QUANTITY TOTAL PRICE
==========================================================
$%
.
format=
@<<<<<<< $@####.## @##### @####.##
$item, $itemprice, $itemnumber, $totalprice
.
open (REPORT, "<a:\\program1.txt"
@lines=<REPORT>;
close (REPORT);
foreach (@lines) {
chop;
($item, $itemprice, $itemnumber, $totalprice)=(split(/!/));
$item=" " if !defined($item);
$itemprice=0 if !defined($itemprice);
$itemnumber=0 if !defined($itemnumber);
$totalprice=0 if !defined($totalprice);
write();
}
<STDIN>;
open (OLDFILE, "<a:\\program1.txt" #retrieve data
@databack=<OLDFILE>; #assigns to array
close(OLDFILE); #closes
foreach (@databack)
{ #creates foreach loop, so each array is split
#and subs are made, subs counted
$count=s/s/x/ig; #saves number of subs to $count
$total=$total + $count; #adds new sub. number to each loop
s/s/x/ig; #subs all s with x
($item, $itemprice, $itemnumber, $totalprice)=split(/, /,); #splits data
}
print "$total "."characters have been substituted.\n\n";
print @databack;
format REPORT_TOP=
========================================================== @<
ITEM PRICE QUANTITY TOTAL PRICE
==========================================================
$%
.
format=
@<<<<<<< $@####.## @##### @####.##
$item, $itemprice, $itemnumber, $totalprice
.
open (REPORT, "<a:\\program1.txt"
@lines=<REPORT>;
close (REPORT);
foreach (@lines) {
chop;
($item, $itemprice, $itemnumber, $totalprice)=(split(/!/));
$item=" " if !defined($item);
$itemprice=0 if !defined($itemprice);
$itemnumber=0 if !defined($itemnumber);
$totalprice=0 if !defined($totalprice);
write();
}
<STDIN>;