why won't this work?

heres some cgi ti've written that refuses to work

sub get_number {

print "number= $num ";


and it refuses to work, it should return the number 1, as that is what is typed in data.txt, but it won't.

Who is Participating?
MaDdUCKConnect With a Mentor Commented:
your code should work, but you did not specifiy the content type. thus, before writing anything to stdout, print the following:

print "Content-type: text/html/r/n/r/n";

or text/plain for text only.

open(NUMBER,"http://username.hypermart.net/data.txt") or print "can't open file because $!";

#open is used to open a filename on the local file system,
#if you want to make an HTTP request over the net, you might

use LWP::UserAgent;
use HTTP::Request;
$ua = LWP::UserAgent->new;
$request = HTTP::Request->new(GET => "http://username.hypermart.net/data.txt");
$response = $ua->request($request);
$num = $response->content;
All Courses

From novice to tech pro — start learning today.