Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re:cgi script

Status
Not open for further replies.

raji96

Programmer
Aug 7, 2001
64
US
Hi,

I am trying to learn cgi scripts and this tutorial i got from a site.How do i test it alone without html interaction?
can i pass the variable on command line,if yes how can i do.
I complied the code and it looks ok.i need to test to see if it is sending me a mail without the variable being passed from the html.

#!/usr/local/bin/perl
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
print "Content-type: text/html\n\n";
print &quot;<HTML>\n&quot;;
print &quot;<BODY BGCOLOR=#FFFFFF>\n&quot;;
print &quot;<CENTER>\n&quot;;
print &quot;YOUR REQUEST HAS BEEN PROCESSED!<BR>\n&quot;;
print &quot;</CENTER>\n&quot;;
print &quot;</BODY></HTML>&quot;;

Thanks.
 
#!/usr/local/bin/perl

if ( @ARGV )
}
foreach @ARGV{push @pairs, $_}
}
elsif ($ENV{'CONTENT_LENGTH')
{
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
}

if (@pairs)
{
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack(&quot;c&quot;,hex($1))/ge;
$fields{$key}=$content;
}
}
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>\n&quot;;
print &quot;<BODY BGCOLOR=#FFFFFF>\n&quot;;
print &quot;<CENTER>\n&quot;;
print &quot;YOUR REQUEST HAS BEEN PROCESSED!<BR>\n&quot;;
print &quot;</CENTER>\n&quot;;
print &quot;</BODY></HTML>&quot;;


Now you can add your name/value pairs on the command line like so:
./somescript.pl name=value name=value name=value etc

This does not send an email. For email you can either fork a process to sendmail or another local smtp server or you can use the Mail::Mailer or MIME::Lite or Net::SMTP (Btw the other two modules actually use this to send to an smtp server, the others are just more user friendly. I generally use MIME::Lite) module in which case you need to know the smtp host name. (There are faqs for sending email.)

HTH,
Johnny
 
you might want to look into indigo perl, it's apache with perl and allows very easy installation of perl modules, and you run it locally, granted you have to come through a browser, so i know this isn't the answer to your question just some food for thought

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top