Patricia E Gorden-Ozgul wrote:
>
> I need help with my $date var. I want it to print at the sixth printf
> position. Can someone help?
>
> Input:
> 18033|18033|89.00|1|182682|20021011|89.00|1|0|0000070001|19724|FIRM|
> 03046|03046|135.93|1|67579558|20020927|135.93|1|0|0000070097|90081|FIRM|
> 08830|08830|88.38|1|182824|20021017|154.26|2|0|0000070001|12435|FIRM|
> 03121|03121|558.81|1|182985|20021022|558.81|1|0|0000070001|15139|FIRM|
> 04500|04500|61.89|1|182988|20021023|61.89|1|0|0000070001|17893|FIRM|
>
> Code:
> #!/usr/bin/perl -w
> #
> # Parse input from invoice file and split into three output files
> # PGO March 2003
> # must run inv_sed against datafile (file9.final) to remove $
>
> # my $date = `date +%Y%m%d`;
> my $datafile = "invshrt";
> open DATA, "< $datafile" || die "Can't open data file: $datafile";
You should include the $! variable in the error message so you know WHY open failed.
> while(<DATA>) {
> chomp;
> my $date = `date +%Y%m%d`;
Do you really want to change $date each time through the loop? You should really use
the POSIX::strftime() function for this as it is a LOT faster.
> my @data = split('\|');
If you are going to use alternate delimiters for the match operator (m//) you should
include the 'm' (m'').
> printf "%-2s%-16s%-8s%-10s%-10s%-7s%-11s%-154s%-7s\n",
> "", $data[4], $data[5], $data[9], "", "", $date, "", $data[6];
1 2 3 4 5 6 7 8 9
You want to print $date at the sixth position but you list it in the seventh position?
printf "%-2s%-16s%-8s%-10s%-10s%-7s%-11s%-154s%-7s\n",
'', @data[4,5,9], '', $date, '', '', $data[6];
> }
> close DATA;
>
> exit 1;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]