GarryRS
Posts: 2
Joined: Mon Dec 23, 2013 2:30 am

Apache2 and Perl cgi-bin

Mon Dec 23, 2013 2:41 am

Hi all,
I've been bashing my head against a perl script that just wont work.

Code: Select all

#!"/usr/bin/perl"
print "Content-type: text/html\n\n";
print "== Perl_embed ==";
$ ./hello.pl give the responce:- -bash: ./hello.pl: "/usr/bin/perl": bad interpreter: No such file or directory
but
$ perl hello.pl give the required response:-
Content-type: text/html
== Perl_embed ==


if I try.
/usr/bin/perl hello.pl
Content-type: text/html

== Perl_embed ==

I get the right response also.

I've done apt-get install perl. and this updated something.

any ideas here would save my sanity.
Thanks in advance,
Garry.

scrapheap
Posts: 20
Joined: Wed Feb 13, 2013 5:13 pm

Re: Apache2 and Perl cgi-bin

Mon Dec 23, 2013 10:53 am

Try dropping the quotes on the first line, so it looks like:

Code: Select all

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "== Perl_embed ==";

GarryRS
Posts: 2
Joined: Mon Dec 23, 2013 2:30 am

Re: Apache2 and Perl cgi-bin

Mon Dec 23, 2013 5:29 pm

yep, it was that easy. Thanks. Two sets of eyes can save your sanity.
Many Thanks.
Garry

User avatar
DougieLawson
Posts: 36841
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Apache2 and Perl cgi-bin

Mon Dec 23, 2013 5:43 pm

Have a look at perl::cgi it doesn't half reduce the amount of coding you need to do CGI.

Code: Select all

<FORM action="http://myhost.mydomain.com/cgi-bin/netm.pl" method="post">
  <INPUT type="hidden" name="html" value="1">
  <P>
  IP Addr ..........
  <INPUT type="text" size="40" name="addr"><BR>
  <BR>
  Mask .............
  <INPUT type="text" size="40" name="mask"><BR>
  <BR>
  <INPUT type="submit" value="Press ENTER">
</FORM>
And the perl

Code: Select all

#!/usr/bin/perl -w

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Net::Netmask;

$query = CGI::new();

$addr = $query->param('addr');
$mask = $query->param('mask');
$html = $query->param('html');

$block = new Net::Netmask($addr, $mask);

if ($html) {
	print $query->header();
	print $query->start_html('Netmask Calc');
	print $query->p;
	print "<table border=1>";
	print "<tr><td><b>";
}
print "IP Addr/Mask:";
if ($html) {print "</b></td><td>";}
print $block->desc()."\n";           # a.b.c.d/bits
if ($html) {print "</td></tr><tr><td><b>Base IP Addr:</b></td><td>";}
else {print "Base IP Addr:";}
print $block->base()."\n";
if ($html) {print "</td></tr><tr><td><b>NetMask:</b></td><td>";}
else {print "Netmask:";}
print $block->mask()."\n";
if ($html) {print "</td></tr><tr><td><b>Broadcast Addr:</b></td><td>";}
else {print "Broadcast Addr:";}
print $block->broadcast()."\n";
if ($html) {print "</td></tr><tr><td><b>Hostmask:</b></td><td>";}
else {print "Hostmask:";}
print $block->hostmask()."\n";
if ($html) {print "</td></tr><tr><td><b>Bits:</b></td><td>";}
else {print "Bits:";}
print $block->bits()."\n";
if ($html) {print "</td></tr><tr><td><b>Size:</b></td><td>";}
else {print "Size:";}
print $block->size()."\n";
if ($html) {print "</td></tr><tr><td><b>Maxblock:</b></td><td>";}
else {print "Maxblock:";}
print $block->maxblock()."\n";
if ($html) {print "</td></tr><tr><td><b>Next Base IP Addr:</b></td><td>";}
else {print "Next Base IP Addr:";}
print $block->next()."\n";
if ($html) {
	print "</td></tr>";
	print "</table>";
	print $query->end_html;
}
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Other programming languages”