http://www.perlmonks.org?node_id=610512


in reply to dynamic website, putting data into right tablefield's

cheers all,
this is my working solution :D,after clearify from bard how to write the hash thingy right ^^

foreach my $prod (@total_pid) { foreach my $su (@total_sup) { $rowhash{$prod}{$su}{'DATA_S'} = ""; $rowhash{$prod}{$su}{'DATA_F'} = ""; } } foreach my $row (@ym_cty_data) { $rowhash{$row->{PRODUCT_ID}}{$row->{SUPPLIER_ID}}{'DATA_F'} = +$row->{VALUE_FE}; $rowhash{$row->{PRODUCT_ID}}{$row->{SUPPLIER_ID}}{'DATA_S'} = +$row->{VALUE_SOLID}; }

first i build the hash with all options, then i fill the options up with data.
with this hash structure you can be sure the data is in the right spot
thx for the help and inspiration
kd ultibuzz

Replies are listed 'Best First'.
Re^2: dynamic website, putting data into right tablefield's
by agianni (Hermit) on Apr 17, 2007 at 17:13 UTC

    Your first step strikes me as unnecessary. I'm guessing that you're trying to avoid accidentally putting data in the wrong cells because some cells data is not there. But as long as you go through all of the products and sups when you output the data, you shouldn't have a problem.

    The benefit of your solution is that you could do something like:

    for my $prod ( keys %rowhash ){ for my $sup ( keys %{$rowhash{$prod}} ){ print "$rowhash{$prod}{$sup}{DATA_F}, $rowhash->{$prod}{$sup}{DA +TA_S}\t"; } print "\n"; }

    ...because all of the options are encapsulated in each row, but that is sort of treating a hash like an array. If you skip your first step of populating the hash with empty values, you should still be able to do something like:

    for my $prod ( @total_pid ){ for my $sup ( @total_sup ){ print "$rowhash{$prod}{$sup}{DATA_F}, $rowhash{prod}{$sup}{DATA_ +S}\t"; } print "\n"; }

    Because you always know what your complete list of products and sups are.

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'

      cheers,
      well the script know of all active products at the now state and all historical active products, that may be inactive or still active.
      anyway i need to treat both of them, if someone wants to edit old data it shoud add the now active products to the historical ones.
      with prebuilding the array with total_pid i get sure all,historical and now, products are in there ;), gives me a better feeling ^^.
      when i only run ym_cty_product i may miss a product.
      when i update/ insert into the database without the first run (empty values i miss some data in db, can be my update/insert sub but with first run everything looks fine in db
      please correct me if i don't get somthing wrong because im quit new into these HoH and so on ^^

      kd ultibuzz

      PS: the data can not be entered in the wrong cell because each cell contains a sup and product, so every value is unique accesible.
      i'will post my table creation tomorrow from office, i think this makes it clearer then my PS ^^

      Update: here is my table code looks a bit messy but it works ^^

      foreach my $row (@total_sup) { my $sup = Get_Supplier_Name($row); print qq(<td align="center" bgcolor="#7E7E7E" colspan="2"><b>$ +sup</b></td>); } print qq(</tr><tr><td align="center" bgcolor="#7E7E7E"><b>Product Name +</b></td>); print qq(<td align="center" bgcolor="#7E7E7E"><b>Flag</b></td>); foreach my $row (@total_sup) { print qq(<td align="center" bgcolor="#7E7E7E"><b>Front End</b> +</td>); print qq(<td align="center" bgcolor="#7E7E7E"><b>Solid Sales</ +b></td>); } print qq(</tr>); foreach my $row (@total_pid) { my $sups = scalar(@total_sup); my $prod_name = Get_Product_Name($row,$group); print qq(<tr><td align="center" bgcolor="#FFFFFF"><input type= +"hidden" name="prod_id" value="$row">$prod_name</td>); print qq(<td align="center" bgcolor="#FFFFFF"><input type="hid +den" name="flag" value="$rowhash{$row}{'FLAG'}">$rowhash{$row}{'FLAG' +}</td>); for (my $i=1;$i<=$sups;$i++) { print qq(<td align="center" bgcolor="#FFFFFF"><input t +ype="text" name="sup_f_$now_sup[$i-1]" value="$rowhash{$row}{$now_sup +[$i-1]}{'DATA_F'}" size="10"></td>); print qq(<td align="center" bgcolor="#FFFFFF"><input t +ype="text" name="sup_s_$now_sup[$i-1]" value="$rowhash{$row}{$now_sup +[$i-1]}{'DATA_S'}" size="10"></td>); } print qq(</tr>); } my $col_span = (scalar(@now_sup)*2)+2; print qq(<tr><td align="center" bgcolor="#7E7E7E" colspan="$col_span"> +<input type="submit" value=" SAVE "></td></tr>);