CGI HoA edit with Storable
Discipulus
created: 2006-01-13 04:14:07
with this u can store on the server an hash of array (with 3 elements in the example).The keys are hidden in the page and are incremental id (1 2 ..).You can add or delete entries and all the resulting hash is stored on the file system.Need grinder.hth lor*
#!perl
use strict;
use warnings;
use CGI qw(:all -nph);
use Storable;

my $hoa = {};
my $file = 'stored.sto';                                             
my $indice = 0;
my @sorted;

print header(),
      start_html(-bgcolor=>"#000099",
                  -text=>"#FF9933",
                  -link=>"#FFFF00",
                  -alink=>"#FFFF00",
                  -vlink=>"#FFFF00");
      print start_form({-name=>'form1'}),
      textfield({-name=>'text1'}),
      textfield({-name=>'text2'}),
      textfield({-name=>'text3'}),
      submit({-value=>'add'}),
      endform();

print hr;

if (-e $file) { $hoa = retrieve $file  }                            

if (defined %$hoa){
    @sorted = sort{ $b <=> $a } keys %$hoa;
    $indice = $sorted[0]+1;
}
###############################################defined param text1
if (defined param('text1')&¶m('text1')=~/\w/) {
     $$hoa{$indice}= [param('text1'),param('text2'),param('text3')];
     store \%$hoa, $file||die "not stored!";                         
     Delete_all();
}
if (-e $file) { $hoa = retrieve $file  }                             
###############################################
foreach my $delenda(keys %$hoa) {
        if (defined param($delenda)) {
            delete $$hoa{$delenda};
        }
}
store \%$hoa, $file||die "not stored!";                              
###############################################
print start_form({-name=>'form2'});
foreach my $k(reverse sort{ $b <=> $a } keys %$hoa) {   #
        print table({-title=>$k,
                     -bgcolor=>"#000000",
                     -border=>1,
                     -bordercolor=>"red",
                     -cellspacing=>"0",
                     -cellpadding=>"0"},
                     td([
                         @{$$hoa{$k}},
                         checkbox(-name=>$k,-label=>'delete')
                        ])
                     ),br;
}
print submit({-label=>'execute'});
print endform();




end_html();

perlmonks.org content © perlmonks.org and Discipulus

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03