in reply to Re: Question on the format statement
in thread Question on the format statement
What is wrong in this piece of code?open DR, ">ddailyreport.prn" or die "Cant open file"; format DATA = @<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @##### @############### + Rs@#####.## ~ $consname, $subdvn, $chequeno, $receiptno, $amount . format TOTAL = -------------------------------------------------------------------- +----------------------- + Rs@#####.## + $total . format TOP = @|||||||||||||||||||||||||||||||||||| Pg @< "Daily Deposit Works Report", $% Consumer name Subdivision Cheque no. Receipt no. + Amount -------------- -------------- ------------- ------------- +- ------- . sub dotize { my($width, $string) = @_; if (length($string) > $width) { return(substr($string, 0, $width - 3) . "..."); } else { return($string); } } $~ = "TOP"; write(DR); open(FILE, "<ddailyreport.txt"); @lines = <FILE>; close(FILE); $total = 0; foreach (@lines) { chop(); ($consname, $subdvn, $chequeno, $receiptno, $amount) = (split(/!/) +); $consname = "" if !defined($consname); $subdvn = "" if !defined($subdvn); $chequeno = 0 if !defined($chequeno); $receiptno = 0 if !defined($receiptno); $amount= 0 if !defined($amount); $~ = "DATA"; write(DR); $total += $amount; } $~ = "TOTAL"; write(DR); close(DR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Question on the format statement
by roboticus (Chancellor) on Apr 01, 2010 at 14:33 UTC | |
by perl_seeker (Scribe) on Apr 06, 2010 at 12:16 UTC | |
by roboticus (Chancellor) on Apr 06, 2010 at 13:48 UTC | |
by perl_seeker (Scribe) on Apr 07, 2010 at 09:38 UTC | |
by roboticus (Chancellor) on Apr 07, 2010 at 18:12 UTC |