I have the following snippet of code that for the most part works correctly. Until it gets to the part where it subtracts. Then who knows what is happening. Here is the code:
### Here is a sample of the input file line: 563,U016228,4,CEL30.0-6/38,Kg,1217,0,1742,0,0,81.5,2070,Kg,trfJPL,81,1 +/2,01/15/02,118,30,tn,01/15/02,01/15/02 #### Code starts here ### foreach $line(<FILE>) { chomp($line); $line =~ s/"//g; $line =~ s/ //g; @record = split(/,/,$line); #### The custhash is created from an index file. if(!defined $custhash{$record[0]}[0]) { print "$line\n"; next; } $salesman = $custhash{$record[0]}[0]; $custnum = $record[0]; #### The next 2 lines are not producing the expected result! $hashlist{$salesman}{$custnum}[6] += $record[5]; $hashlist{$salesman}{$custnum}[6] -= $record[7]; ##### These 3 lines I used for debug and the results are ??? $orders += $record[5]; $shipments += $record[7]; $openorders += $hashlist{$salesman}{$custnum}[6]; #on hand inventory $hashlist{$salesman}{$custnum}[8] += $record[6]; @duedate = split(/\//,$record[16]); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; if(($duedate[0] == ($mon+1)) && ($duedate[2] == ($year-100))) { #due this month $hashlist{$salesman}{$custnum}[7] += $record[9]; } } close (FILE); #### These lines are accurate data... $calcorders = $orders - $shipments; print "mk_sales1.pl orders=$orders shipments=$shipments\n"; print "mk_sales1.pl open=$openorders calc open=$calcorders\n"; exit;
Here is an example of the output:
mk_sales1.pl orders=4555921.98401899 shipments=1018457.10569 +208 mk_sales1.pl open=162276886.110807 calc open=3537464.87832691
The expected result is orders - shipments = open. However you get orders - shipment = calcopen. And calcopen should = open. In case you are wondering calcopen is accurate.. Hmmmm ???

In reply to Problem subtracting in Perl by diakonos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.