why won't this work?

heres some cgi ti've written that refuses to work

sub get_number {

 open(NUMBER,"http://username.hypermart.net/data.txt");
 $num=<NUMBER>;
 close(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.

thanks.
pobwestAsked:
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.


0
 
ozoCommented:
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;
0
All Courses

From novice to tech pro — start learning today.