Newsgroup: it.comp.lang.perl
Titolo: aiuto per i sub - per favore

Ciao a tutti sono un novizio e ho bisogno d'aiuto
Sto cercandoi di accedere ad una subroutine direttamente da un link.
Mi spiego meglio: ho una sub che si chiama 'job' e voglio poter
eseguire questa sub da un link
##### job
sub job { 
&header
... 
&footer
exit; 
} 
##### 
e come link uso 
http://www.mysite.com/mycgi.pl?job
 
Per qualche motivo però il mio script viene eseguito tutto quando
faccio così. Cosa sbaglio?
Grazie dell'aiuto
Alberto

 faccio così. Cosa sbaglio?
Non sbagli niente, è il funzionamento normale. Potresti provare con...
-----
#!/usr/bin/perl
use CGI header,param;
$funzione = param('funzione');
print header('text/html');
&$funzione;
exit;
sub job {
    print "Sono job!";
}
sub wait {
    print "Sono wait!";
}
-----
E lo chiami con script.cgi?funzione=job oppure funzione=wait.
Ciao,
Valerio
--
Valerio Granato - 
val...@grana.to
FOR KeyMaster - i2000 Usenet Hierarchy
Maggiori informazioni sulla gerarchia i2000?
http://www.i2000.usenet.it
 - 
in...@i2000.usenet.it

Non sbagli niente, č il funzionamento normale. Potresti provare con...


 sapresti dirmi il perché?
Purtroppo no :-(
Magari se posti tutto il pezzo di codice...


se ci riesci sei un grande: il sub che vorrei chiamare č sub post_box
questa č la versione che funziona. quando lo modifico rimuovo l'ultimo
if (@board[4]==1) {
&post_box;
}
prima del sub post_box
e aggiungo
&header;
e
&footer;
exit;
all'interno delle parentesi
ti ringrazio molto per il tempo che dedichi
Alberto
************
#!/usr/bin/perl
$fullpath="./";
push(@INC, $fullpath);
##don't change this variable unless you know what you are doing
$display_pl="
display.pl
";
$bench="0";
###You may need to change following variables to full system path if
you are using windows servers
$mcfg="
mcfg.pl
";
$vcfg="
vcfg.pl
";
#
$start=(times)[0];
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/\s/g;
if ($name && $value) { $input{$name} = $value; }
if ($value=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Content-type: text/html\n\n";
&header;
print "<b>Azione cancellata</b>\n";
print "Per favore non usare simboli particolari.\n";
&footer;
exit;
}
}
eval {
require "$mcfg";
require "$vcfg";
};
if ($@) {
&error("Unable to load $mcfg and $vcfg. Please check out the readme
file.");
}
$input{'board'}=~ tr/A-Z/a-z/;
$input{'board'}=~ s/\s//g;
if (!$input{'board'} or $input{'board'} eq "--") {
&jump("1");
}
open (board, "<$bdata/$input{'board'}.bd") or &jump("2");
if ($flock eq "y") {
flock board, 2;	
}	
@board=<board>;
close (board);
chomp(@board[0]);
chomp(@board[1]);
chomp(@board[2]);
chomp(@board[3]);
chomp(@board[4]);
$messages=@board[0];
$messages2=@board[1];
sub jump {
require "$display_pl";
exit;	
}	
print "Content-type: text/html\n\n";
if ($input{'ptime'}>0 and $input{'ptime'}<=90) {
$time_period=$input{'ptime'};
}
$string = "all";
if (!$input{'ptime'} and $custom_day !=~ /$string/i) {
$input{'ptime'}=$time_period;
}
if (lc($input{'ptime'}) eq "all" and $custom_day =~ /$string/i) {
$time_period=0;
}
else {
$time_period = time() - ($time_period * 86400);#set time period for
displaying messages
}
&getMessageIndex;
sub getMessageIndex {
open (indexcount, "<$bdata/$input{'board'}.txt") or &error("Unable to
open the counting file- $input{board}.txt");
$indexcount=<indexcount>;
close (indexcount);
$total=0;
$indexcount--;
Getting:for ($indexcount; $indexcount>0; $indexcount--) {
open (content, "<$messages/$indexcount.dat") or next Getting;
@content=<content>;
close (content);
@content[2]>$time_period?$order[$total]="@content[2]x$indexcount":return;
$total++;
}
}
if ($sort_it eq "y" and $total>0) {
@order=sort(atob @order);
}
sub atob {
$b<=>$a;
}
#start to create the message index page
if ($input{'next'} and $input{'next'}<$total and $input{'next'}>=0) {
@order=splice(@order, $input{'next'}); 
}
else {
$input{'next'}=0;	
}	
&header;
if ($btitle eq "y") {
print "<font color=\"$other_color\"
face=\"$font_face\"><b>@board[2]</b>";
if (@board[3]==0) {
print " [Private Board]";
}	
print "</font><br><br>\n";	
}
$num=0;
if ($time_select eq "y") {
$custom_day=~s /\s//g;
@time_frames=split(/,/, $custom_day);
print "<table border=\"0\" width=\"$table_width\">\n
<tr valign=\"bottom\"><td>
<form action=\"$cgi2\" method=\"get\"><input type=\"hidden\"
name=\"board\" value=\"$input{'board'}\"><select name=\"ptime\">
<option  value=\"1\" selected>ultimo giorno</option>";
foreach $time_frame(@time_frames) {
if (lc($time_frame) eq "all") {
lc($input{'ptime'}) eq "all"?print "<option  value=\"$time_frame\"
selected>show all topics</option>":print "<option
value=\"$time_frame\">tutti i messaggi</option>";
}
else {
$time_frame==$input{'ptime'}?print "<option  value=\"$time_frame\"
selected>ultimi $time_frame giorni</option>":print "<option
value=\"$time_frame\">ultimi $time_frame giorni</option>";
}
}
print "</select> <INPUT TYPE=image src=\"/images/invia.gif\" border=0
width=\"42\" height=\"23\"></form>
</td><td align=\"right\"><font face=\"Tahoma\" size=\"2\"><a
href=\"$cgi2?board=board1&post_box\">Nuovo messaggio</a> | <a
href=\"/help.htm#forum\">Help</a></font><br></td></tr></table>";
}
print "<table border=\"0\" width=\"$table_width\">\n
<tr valign=\"top\"><td></td></tr><tr valign=\"top\"><td></td>
<td bgcolor=\"$title_color\" width=\"280\"><font color=\"$title_text\"
face=\"$font_face\"
size=\"$font_size\">&nbsp;Oggetto&nbsp;</font></td>\n
<td bgcolor=\"$title_color\" width=\"150\"><font color=\"$title_text\"
face=\"$font_face\"
size=\"$font_size\">&nbsp;Autore&nbsp;</font></td>\n
<td bgcolor=\"$title_color\" width=\"55\"><font color=\"$title_text\"
face=\"$font_face\"
size=\"$font_size\">&nbsp;Risposte&nbsp;</font></td>\n
<td bgcolor=\"$title_color\" width=\"115\"><font color=\"$title_text\"
face=\"$font_face\" size=\"$font_size\">&nbsp;Ultimo
messaggio&nbsp;</font></td></tr>\n";
if ($total==0) {
print "<tr><td valign=\"top\"></td><td bgcolor=\"$topic_color\"><img
src=\"$default_icon\" border=\"0\"> <font color=\"$topic_text\"
face=\"$font_face\" size=\"$font_size\">No messages were
posted.</font></td>";
print "<td bgcolor=\"$replies_color\" align=\"center\"><font
color=\"$replies_text\" face=\"$font_face\"
size=\"$font_size\">-</font></td>\n";
print "<td bgcolor=\"$post_color\" align=\"center\"><font
color=\"$post_text\" face=\"$font_face\"
size=\"$font_size\">-</font></td><td bgcolor=\"$lastpost_color\"
align=\"center\"><font color=\"$lastpost_text\" face=\"$font_face\"
size=\"$font_size\">-</font></td></tr></table>\n";
&skip;
}
@months =
('January','February','March','April','May','June','July','August','September','October','November','December');
@days =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
Opening:foreach $order (@order) {
@xorder=split (/x/, "$order");
open (data, "<$messages/@xorder[1].dat") or next Opening;
if ($flock eq "y") {
flock data, 2; 
}
@data=<data>;
close (data);
#time
chomp(@data[2]);
($sec,$min,$hour,$mday,$mon,$year,$wday) =
(localtime(@data[2]))[0,1,2,3,4,5,6];
$sec = sprintf("%.02d",$sec);
$min = sprintf("%.02d",$min);
$hour = sprintf("%.02d",$hour);
$mday = sprintf("%.02d",$mday);
$year += 1900;
#date format
if ($date_format==1) {
$date = "$days[$wday], $months[$mon] $mday, $year at $hour:$min:$sec";
}
elsif ($date_format==2) {
$mon++;
$date = "$mday/$mon/$year $hour:$min";	
}
else {
$mon++;
$date = "$mon/$mday/$year $hour:$min:$sec";	
}		
#
$num++;
if (!@data[4]) {
@data[4]=$default_icon;	
}	
print "<tr valign=\"top\"><td valign=\"top\"></td><td
bgcolor=\"$topic_color\"><img src=\"/images/folder.gif\" border=\"0\">
<font face=\"$font_face\" size=\"$font_size\"><a
href=\"$messages2/@xorder[1].$file_ending\">@data[0]</a></font></td>
<td bgcolor=\"$post_color\"><font color=\"$post_text\"
face=\"$font_face\" size=\"$font_size\">@data[3]</font></td>
<td bgcolor=\"$replies_color\"><font color=\"$replies_text\"
face=\"$font_face\"
size=\"$font_size\"><center>@data[1]</center></font></td>
<td bgcolor=\"$lastpost_color\"><font color=\"$lastpost_text\"
face=\"$font_face\" size=\"$font_size\">$date</font></td></tr>\n";
if ($num==$max) {
print "</table>\n";
if ($a_search) {
&search;
}
&links;
if (@board[4]==1) {
&post_box;
}
if ($bench==1) {
$end=(times)[0];
print "<br>It took ", ($end - $start) , " second to complete this job
(start: $start end $end)";
}
&footer;
exit;	
}
}
sub skip {
if ($a_search) {
&search;
}
&links;
if (@board[4]==1) {
&post_box;
}
if ($bench==1) {
$end=(times)[0];
print "<br>It took ", ($end - $start) , " second to complete this job
(start: $start end $end)";
}
&footer;
exit;	
}
print "</table>\n";
if ($a_search) {
&search;
}
&links;
if (@board[4]==1) {
&post_box;
}
if ($bench==1) {
$end=(times)[0];
print "<br>It took ", ($end - $start) , " second to complete this job
(start: $start end $end)";
}
&footer;
exit;
#######post box
sub post_box {
print "<br><br><br>\n";
if ($opticon eq "y") {
open (icon, "<$fullpath/iconbase.dat") or &error("Unable to open
iconbase.dat");
if ($flock eq "y") {
flock icon, 2; 
}
@icon=<icon>;
close (icon);
}
print "<font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">
<b>Nuovo messaggio:</b>";
print "</font><br><br>\n
<table border=\"0\">\n
<form action=\"$cgi\" method=\"post\">\n
<tr><td><font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">Nome:</font></td><td><input type=\"text\"
name=\"name\" maxlength=\"20\"></td></tr>\n
<tr><td><font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">E-mail:</font></td><td><input type=\"text\"
name=\"email\" maxlength=\"50\"></td></tr>\n";
if ($replymail eq "y") {
print "<tr><td></td><td><font color=\"$other_color\"
face=\"$font_face\" size=\"$font_size\">Avvertimi quando c'č una
risposta:<input type=\"radio\" name=\"ereply\" value=\"yes\">Sě
&nbsp;<input type=\"radio\" name=\"ereply\" value=\"no\"
checked>No</font><br><br></td></tr>\n";
}
if ($opticon eq "y") {
print "<tr><td valign=\"top\"><font color=\"$other_color\"
face=\"$font_face\"
size=\"$font_size\">Icons:</font></td><td>@icon<br><br></td></tr>\n";
}
print "<tr><td><font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">Oggetto:</font></td><td><input type=\"text\"
name=\"subject\" maxlength=\"50\"></td></tr>\n
<tr><td valign=\"top\"><font color=\"$other_color\"
face=\"$font_face\" size=\"$font_size\">Messaggio:</font></td><td
valign=\"top\"><textarea name=\"message\" cols=\"50\" rows=\"10\"
wrap=\"physical\"></textarea>\n
<input type=\"hidden\" name=\"action\" value=\"preview\"><input
type=\"hidden\" name=\"board\" value=\"$input{'board'}\"></td></tr>\n
<tr><td></td><td><font face=\"$font_face\"><INPUT TYPE=image
src=\"/images/invia.gif\" border=0 width=\"42\"
height=\"23\"></font></form></td></tr>\n
</table>";
}
#####quick search
sub search {
print "<table border=\"0\"><tr><td><form action=\"$search\"
method=\"post\"><font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">Cerca: </b><select name=\"field\"><option
value=\"1\">Oggetto<option vaue=\"2\">Autore </select><input
type=\"text\" size=\"25\" name=\"keyword\">
<input type=\"radio\" name=\"match\" value=\"all\" checked><font
face=\"$font_face\" size=\"$font_size\"> Tutte </font>
<input type=\"radio\" name=\"match\" value=\"any\"><font
face=\"$font_face\" size=\"$font_size\"> Almeno una </font>
<input type=\"radio\" name=\"match\" value=\"exact\"><font
face=\"$font_face\" size=\"$font_size\"> Esatta </font>
<INPUT TYPE=image src=\"/images/cerca.gif\" border=0 width=\"49\"
height=\"23\">
<input type=\"hidden\" name=\"board\" value=\"$input{'board'}\">
</form></font></td></tr></table>"; 
}
#####################links
sub links {
print "<font color=\"$other_color\" face=\"$font_face\"
size=\"$font_size\">";
print "<br>Pagina: ";
$link=int($total/$max);
$link2=$total%$max;	
unless ($link2==0) {
$link++;	
}
$next=0;	
$count=1;
for ($count; $count<=$link; $count++) {
if ($input{'next'}==$next) {
print "<b>$count</b> ";
$next=$next+$max;
}
else {
print "<a
href=\"$cgi2?board=$input{'board'}&next=$next\&ptime=$input{'ptime'}\">$count</a>
";
$next=$next+$max;	
}
}
print "</font>";
}
######################header input
sub header {
open (header, "<$fullpath/vheader.txt") or &error("Unable to open the
vheader file");
if ($flock eq "y") {
flock header, 2; 
}
@header=<header>;
close(header);
print @header;
}
####################footer input
sub footer {
open (footer, "<$fullpath/vfooter.txt") or &error("Unable to open the
vfooter file");
if ($flock eq "y") {
flock footer, 2; 
}
@footer=<footer>;
close(footer);
print @footer;
}
#####error
sub error {
print "<h2>An error has occured</h2> The error is $_[0]<br>\n";	
print "Reason: $!\n<br><br>";
print "Please contact the webmaster of this web site if you keep
getting this message.";	
exit;	
}

 sapresti dirmi il perché?
Prova ad eseguire lo script direttamente dall'interprete Perl, che ti
avvertirà di (eventuali) errori. (mal che vada, #!perl -w)
-- 
echo f 0:0 ffff 0 | debug
La leggerezza del VOLER essere ....

avvertirą di (eventuali) errori. (mal che vada, #!perl -w)
?
e sopra tutto dove trovo un interprete?

 all'interno delle parentesi
Quali parentesi?
Ciao,
Valerio


 e sopra tutto dove trovo un interprete?
Vuoi dirmi che carichi gli script "al buio" e li provi direttamente
online? Scaricati l'interprete Perl (
www.activestate.com
, se sei su win)
ed un webserver e, prima di testare lo script in remoto (che tra l'altro
costa, a meno che hai una linea dedicata o adsl) fatti le prove in
locale!
