Since
unpack returns strings of zero length, you can check with
length:
use warnings;
use strict;
printf("%-11s %-27s %9s %11s","Date","Description","Incoming","Outgoin
+g\n");
my $x = 0;
my $tot;
my $totex;
while (<DATA>) {
if ($x==0) {$x++;next;}
my ($date,$des,$inc,$exp) = unpack("A10 A27 A10 A*", $_);
$inc = 0 unless length $inc;
$exp = 0 unless length $exp;
printf("%-10s %-27s %10.2f %10.2f\n",$date,$des,$inc,$exp);
$tot += $inc;
$totex += $exp;
}
printf("%38s %10.2f %10.2f","Totals",$tot,$totex);
print "\n";
__DATA__
Date Description incoming outgoing
01/24/2001 Zed's Camel Emporium 100.00 1147.99
01/28/2001 Flea spray 24.99
01/29/2001 Camel rides to tourists 235.00
01/31/2001 avage1 125.00
01/20/2001 carpe diem 20.00 23.00
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.