majo has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone. Is it possible to run either of these codes from HTML Thanks majo

#!/usr//bin/perl -w use LWP::UserAgent; use Time::HiRes 'time','sleep'; $ua = LWP::UserAgent->new; $request = new HTTP::Request('GET', "http://http://www.computerhope.co +m/file.com"); $start = time( ); $response = $ua->request($request); $end = time( ); $latency = $end - $start; print length($response->as_string( )), " bytes received in $latency s +econds\n";
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use LWP::UserAgent; my $urlin = shift || "http://zentara.net/zentara.avi"; my $infile = "zentara1.avi" ; print "gettin video file : $infile\n"; # don't buffer the prints to make the status update $| = 1; open(IN,"> $infile") or die "$_\n"; my $ua = LWP::UserAgent->new(); my $received_size = 0; my $request_time = time; my $last_update = 0; my $response = $ua->get($urlin, ':content_cb' => \&callback, ':read_size_hint' => 8192, ); print "\n"; close IN; #play the avi file with mplayer # system( "mplayer $infile" ); ############################################# sub callback { my ($data, $response, $protocol) = @_; my $total_size = $response->header('Content-Length') || 0; $received_size += length $data; # write the $data to a filehandle or whatever should happen # with it here. print IN $data; my $time_now = time; # this to make the status only update once per second. return unless $time_now > $last_update or $received_size == $total_s +ize; $last_update = $time_now; print "\rReceived $received_size bytes"; printf " (%i%%)", (100/$total_size)*$received_size if $total_size; printf " %6.1f/bps", $received_size/(($time_now-$request_time)||1) if $received_size; } __END__

Replies are listed 'Best First'.
Re: RUN A FILE FROM HTML
by tobyink (Canon) on May 10, 2012 at 13:55 UTC

    HTML is a document format, and as such doesn't "do" anything.

    It can contain instructions which when followed by a browser, can cause that browser to do something; or instructions that when followed by a browser, can cause the browser to ask a web server to do something.

    Please explain the end result you hope to achieve and we'll let you know the best way of achieving it.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Hi Tobylink. thanks for the reply What I want call the file from HTML. Is it possible to use hyperlink?The result I want is exactly the result I want when I run the file in perl that is ti print the result which is the latency result and also save this result into text or html file Thanks

        I think what you mean is that you want to make these scripts run on a web server and display their results on a web page. By the sounds of it you don't have a clear understanding of what server side scripting is, and what HTML is. There is a bit of a learning curve, I think the best place for you to start would be with Ovid's CGI Course (see also the Web Programming section of tutorials). Once you have specific questions please let us know what you need help with.

    A reply falls below the community's threshold of quality. You may see it by logging in.