in reply to CGI script returns no values in browser but is ok on command line?

This may or may not help fix the issue, but the fatalsToBrowser will be much more verbose with the use of strict and warnings. Usually something most beginners either forget or sometimes don't realize are there.

You will have to define your variables (because of strict), yet the modules together will show you *everything* that's syntactically wrong.

In your example:
#!/usr/bin/perl # Use the modules here! use strict; use warnings; BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); } $kjarnavelar = "9"; $i = "0"; $rbports = "0"; $oraports = "0"; @host = ("x00802","x00803","x00804","x00902","x00903","x00904","xb0011 +2","xb00113","xb00114"); foreach $host (@host) { $rbport = `/usr/bin/telnet $host 1367 |egrep -v "Trying|Connec +|Escape"`; $rbarray[$i] = "$rbport"; $oracle = `/usr/bin/telnet $host 1371 |egrep -v "Trying|Connec +|Escape"`; $oraarray[$i] = "$oracle"; $oraports = $oraports+$oracle; $rbports = $rbports+$rbport; $i++; } print "<HTML>"; print "<TABLE BORDER=1>"; print "<TR><TD><B>Host</TD><TD><B>RB Ports Active</TD><TD><B>Oracle Po +rts Active</TD></TR>"; for($start=0;$start<=$kjarnavelar;$start++) { print "<TR><TD>$host[$start]</TD><TD>$rbarray[$start]</TD><TD> +$oraarray[$start]</TD></TR>"; } print "</TABLE>"; print "<TABLE BORDER=1>"; print "<TR><TD><B>Samtals RB Port</TD><TD><B>Samtals Oracle Port</TD>< +/TR>"; print "<TR><TD>$rbports</TD><TD>$oraports</TD></TR>"; print "</TABLE>"; print "</HTML>";
Hope that helps!

---------
perl -le '$.=[qw(104 97 124 124 116 97)];*p=sub{[@{$_[0]},(45)x 2]};*d=sub{[(45)x 2,@{$_[0]}]};print map{chr}@{p(d($.))}'

Replies are listed 'Best First'.
Re^2: CGI script returns no values in browser but is ok on command line?
by TOD (Friar) on Jan 26, 2007 at 06:44 UTC
    additionally you should tell the browser of what content-type the response is. try sending a 'text/html' first before you print the document.