BikerDuck has asked for the wisdom of the Perl Monks concerning the following question:

trying to create a particular app for sending a Bill of lading to vendors. I start with a database call and get the list of items to display. then one of our users fills in the approprite quantities and i want to send an e-mail of only the lines where data was filled into the form fields. can someone point me to a good method of doing this aside from trying to pass the entire hash after submitting the form? The snippet below is how i was putting all of the fields into the array and then trying to pass the array to an e-mail script. it just seems unruly and that there would be a much more efficient method.. Thanks for any help. ....
my $ordno = 1; while (my $ref = $GetWOData->fetchrow_hashref()) { my $ordslice = 1; print "$ref->{'Ord_No'}\n"; $orders[$ordno]->[$ordslice] = "$ref->{'Ord_No'} | $ref->{'Item_No'} +"; $ordslice++; print "$ref->{'Item_No'}\n"; print "<input type=\"text\" name=\"qty$ordno\" value=\"\" size=\ +"6\">\n"; #Qty of parts $orders[$ordno]->[$ordslice] = "0"; $ordslice++; print "$ref->{'Item_Desc_1'}\n"; $orders[$ordno]->[$ordslice] = "$ref->{'Item_Desc_1'} | $ref->{'Item +_Desc_2'}"; $ordslice++; print "<input type=\"text\" name=\"skd$ordno\" value=\"\" size=\" +6\">\n"; #Num of skids $orders[$ordno]->[$ordslice] = "0"; $ordslice++; print "$ref->{'Cus_Name'}\n"; $orders[$ordno]->[$ordslice] = "$ref->{'Cus_Name'}"; $ordno++; } $GetWOData->finish();

Replies are listed 'Best First'.
Re: looking for better solution
by NetWallah (Canon) on Nov 01, 2007 at 13:42 UTC
    Your description seems to go completely against the "best practice" of separating the "data storage/management" from the "business logic" and the UI.

    It is not at all clear from your code where you are obtaining and storing the data, and what is being passed to what.

    That said, If I were to design this app/DB, I would display a form asking for quantities ordered, store that quantity , and date requested into a database table , then use a separate program to email or print the invoice (This program would read from the Database - no structure should get passed, perhaps some simple scalars for customer number, date, or possibly an invoice number (for possible re-printing,e-mail). Such a request could/should also be made via a database record, so that a record of request completion can be kept.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

Re: looking for better solution
by ides (Deacon) on Nov 01, 2007 at 13:53 UTC

    This doesn't directly address your question, but will make your life in general a ton easier... Stop hard coding HTML into your applications and use a templating system like Template-Toolkit or HTML::Template

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: looking for better solution
by BikerDuck (Initiate) on Nov 01, 2007 at 14:20 UTC
    Thanks frank.. i'll look into Html::Template. Sorry for the ambiguity about the data. I am pulling the data from a database from our main business system (pervasive-SQL) and a table in there that stores all of the work orders for our shop. So in my call i pull all of the lines that have a possibility of being sent out for processing. That's where i need to create this bill of lading and e-mail it to the vendor. Not all of the lines of data are sent to the vendor. Only the lines that the user enters a number into. SO i need to detect which lines have a skid and part qty, stick that into an e-mail and send.. ( using Mail::Sender ) That mail is not a problem.. the main question is how to only grab the appropriate lines from the table and put it into an array..

      Couldn't you use a where clause in the sql query to only grab the ones with quantity and skid set?

      Your code is pretty confusing for a couple reasons. The use of print mixed in with your insertion of text into an array ref mixed with that incrementing variable makes it hard to follow.

      The following does the same thing as your code does, but I think it makes it clear exactly what is going on. I'm still confused by the mix of printing plain text with HTML, and the strings your are putting into the array are odd as well.

      my $ordno = 1; while (my $ref = $GetWOData->fetchrow_hashref()) { print "$ref->{'Ord_No'}\n"; print "$ref->{'Item_No'}\n"; print "<input type=\"text\" name=\"qty$ordno\" value=\"\" size=\ +"6\">\n"; #Qty of parts print "$ref->{'Item_Desc_1'}\n"; print "<input type=\"text\" name=\"skd$ordno\" value=\"\" size=\ +"6\">\n"; #Num of skids print "$ref->{'Cus_Name'}\n"; push @{$orders[$ordno]}, "$ref->{'Ord_No'} | $ref->{'Item_No'}"; push @{$orders[$ordno]}, "0"; push @{$orders[$ordno]}, "$ref->{'Item_Desc_1'} | $ref->{'Item_Desc_ +2'}"; push @{$orders[$ordno]}, "0"; push @{$orders[$ordno]}, "$ref->{'Cus_Name'}"; $ordno++; } $GetWOData->finish();

      ___________
      Eric Hodges
        Thanks.. i'll use the push method to build the array.

        I think i found a solution to what i want to do.. Using CGI::Ajax i think i can output this table with the form elements, and then only put items in the array when they enter data.

        The query problem is that the Quantity can change on the Floor (Scrap) and Skid quantity will also change dynamically so i can't grab that data.. i have to rely on users to input that

        I will post final outcome once i work out all of the little details..
Re: looking for better solution
by TOD (Friar) on Nov 01, 2007 at 13:22 UTC
    that's a bit cryptic so far. i confess that i really don't understand what you mean.
    --------------------------------
    masses are the opiate for religion.