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

Dear monks,

I have a log file were one of my scripts stores data about webservers. There are 16 entries. Now I wont create a CGI (I run win IIS unfortunatly..) to search these entries belonging two index of the entries: until now all is OK:
#$cosa is the first parameter of the request while (<LOGFILE>) { push(@logline, $_); } ... foreach $record(@logline) { my @ciccio=split/\?/,$record; pop @ciccio; if ($ciccio[2]=~/$cosa/ || $ciccio[3]=~/$cosa/ || $ciccio[14]=~/$co +sa/ ) { $indice++; print table({-border=>0,-width=>"100%", -cellspacing=>"0", -cellpa +dding=>"0"}, Tr({-align=>LEFT,-valign=>TOP}, [ td([$q->h5("$indice)"),"$ciccio[0]","poiiiii $risultato_pin +g"]), td([$q->a({-href=>"http://$ciccio[2]",target=>new},"$ciccio +[2]"),"$ciccio[4]"]), td(["$ciccio[3]","$ciccio[7]"]), td(['',"$ciccio[9]"]), td(['',"$ciccio[10]"]), td(['',"$ciccio[11]"]), td(['',"$ciccio[14]"]), td(['',"$ciccio[15]"]), td([''," "]) ] ) );
now I want for the every entry that match I want some bottons to do stuff for example to ping this hostname and verify if it pings on the machine where it resides.. and others command that can run on the server.. and here start my problem..
print $q->start_form(-method=>'POST',-action=>'formDB.cgi'); print $q->hidden(-name=>'ping',-value=>"$ciccio[2]"); print $q->submit('PING'); print $q->hr; } } } #... if (defined ($pingalo = $q->param('ping'))) { open (FH,"ping -n 1 -l 1 $pingalo|"); while (<FH>){if ($_=~/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){$risult +ato_ping=$1}} close FH; }
ID EST: I search for www.perl.it ... I find it out and I print a breakline, the table of results where the www.perl.it is a link to the site (until now all good..)then it appears a beatiful botton named PING and I want that if you click it in the table will appears in the first row at the third place the IP of the host ..

I whish other bottons that store their value and if u click it they runs command..

So, some summer suggestions sirs ??

greetings from sunny boiled roma
lor*

Replies are listed 'Best First'.
Re: CGI command newbie question
by benn (Vicar) on Aug 07, 2003 at 14:22 UTC
    Errmmm...I *think* you're looking for a generic mechanism to add various buttons and then act on them - maybe something like this (untested)...?
    my @commands = qw(ping traceroute whois other stuff); print $q->start_form(-method=>'POST',-action=>'formDB.cgi'); print $q->hidden(-name=>'val',-value=>"$ciccio[2]"); print $q->submit(uc($_)) foreach (@commands); print $q->end_form;
    ...then you could maybe use a dispatch table...something like...
    my $dispatch = { ping => sub { return my_ping($_[0])}, traceroute => sub { return my_traceroute($_[0])}, etc. => }; foreach (@commands) { $dispatch->{$_}->($q->param('val')) if (defined $q->param(uc($_))); }
    Hope this helps, Ben.