I am trying to write a script which retrives some sales related information from a database, sorts it by the name of the vendor it was purchased from, and then formats it so it can be printed with Win32::Printer. After a vendors items have been printed out I want to print some totals (purchasing costs... etc) and then start the next vendor on a new page. This is where I am having a problem, my script prints the totals from the current vendor under the previous venders items. Heres an example of the error
#2 INVENTORY REPORT BY VENDOR Page No. 1 VEN ITEM DWT DWT COST DOR COST ----------------------------------- ??? 2241 0.00 0.00 165.00 ??? 2391 0.00 0.00 185.00 ??? 2443 0.00 0.00 395.00 #ITEMS TOTAL DWT TOTAL DWT COST -------------------------------- 41 63.95 93920.00 #2 INVENTORY REPORT BY VENDOR Page No. 1 VEN ITEM DWT DWT COST DOR COST ----------------------------------- A&A 2743 0.00 0.00 225.00 #ITEMS TOTAL DWT TOTAL DWT COST ------------------------------- 3 0.00 0.00

The vendor A&A's totals give the information for the previous vendor ???

Heres my script:

use DBI; require formats.pl; $dbh = DBI->connect("dbi:SQLite:dbname=K&M","","") || die "\nCan't ope +n Database!\n"; $row = $dbh->selectrow_arrayref( "SELECT COUNT(*) from INV" ); $count = $row->[0]; $results = $dbh->selectall_arrayref("SELECT * FROM INV ORDER BY VENDOR +, CODE"); open INVENTORY,">print.txt"; select INVENTORY; my $inventory_format = select(INVENTORY); $^L = ""; $= = 54; select($inventory_format); for(my $i=0; $i <= $count; $i++) { $user = $results->[$i]; if ($vendor ne $user->[6]) { $left=$-; $dap=$%; close($inventory_format); close INVENTORY; open TOTALS,">>print.txt"; select TOTALS; my $totals_format = select(TOTALS); $^L = ""; $= = 54; select($totals_format); $-=$left; write; $left=$-; for(my $y=$left;$y>=1;$y--){ print "\n"; } $TOTAL_ITEMS=0; $TOTAL_DWT=0; $TOTAL_DWT_COST=0; $TOTAL_COST=0; $TOTAL_PRICE=0; open INVENTORY,">>print.txt"; select INVENTORY; my $inventory_format = select(INVENTORY); $^L = ""; $= = 54; select($inventory_format); $- = 0; } $vendor=$user->[6]; write; $TOTAL_ITEMS++; $TOTAL_DWT+=$user->[1]; $TOTAL_DWT_COST+=$user->[0]; $TOTAL_COST+=$user->[2]; $TOTAL_PRICE+=$user->[3]; }

I would just like to thank anyone in advance for taking the time to figure out what the heck I'm talking about, because I feel like my explination isn't very good. Thank you in advance for any help you could possible give.


In reply to Help with Perl Format Footers by Anonymous Monk

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.