What is going on?

G

giraffe6044

I was given this perl script as a example of a program to control our
remote powerdevices. Problem is i do not know Perl. I am creating the
site in Coldfusion
Can someone help explain to me what this script is doing to get the
STATUS of the RPS.

is it a form post? or is it requesting a URL and if so what URL.

here is the device.
http://www.digital-loggers.com/EPC.html

Thank you very much for any help

#!/usr/bin/perl -w
#----------------------------------------------------------------------
use LWP::UserAgent;
#----------------------------------------------------------------------
$ua = LWP::UserAgent->new();
#----------------------------------------------------------------------

if ($#ARGV <= 1)
{
print STDERR 'Usage: UserUtil <Host>[:port] <login:password>
<[n]{on|off|pulse|status}> ...'."\n";
exit -1;
}
($epc, $auth)=splice(@ARGV,0,2);
$base='http://'.$auth.'@'.$epc.'/';

foreach (@ARGV)
{
$_=lc;
s/(^[^1-8])/a$1/;
if (/^([1-8a])on$/)
{
RelLink('outleton?'.$1);
}
elsif (/^([1-8a])off$/)
{
RelLink('outletoff?'.$1);
}
elsif (/^([1-8a])pulse$/)
{
RelLink('outletgl?'.$1);
}
elsif (/^([1-8a])status$/)
{
$n=$1;
defined($response) && ($response->content =~/<a href=outleto/) ||
RelLink('');
$content=$response->content;
while ($content =~ /<a href=outlet(on|off)\?([1-8])>/ig)
{
if (($2 eq $n) || ($n eq 'a'))
{
if ($1 eq "on")
{print $2," OFF\n";}
else
{print $2," ON\n";}
}
}
}
else
{
die "Unknown command $_\n";
}
}

sub RelLink
{
local ($_) = @_;
#print STDERR $base.$_,"\n";
$response = $ua->get($base.$_);
$response->is_error() && die $response->status_line;
}
 
T

Tad McClellan

Subject: What is going on?


You will greatly increase the chances of getting your question
answered if you put the subject of your article in the Subject
of your article.

I was given this perl script as a example of a program to control our
remote powerdevices. Problem is i do not know Perl.


You could learn Perl or you could hire someone who knows Perl or
you could ask whoever provided you with that code.

Can someone help explain to me what this script is doing to get the
STATUS of the RPS.


What is an "RPS" ?

is it a form post?


It makes an HTTP GET request.

or is it requesting a URL


Even POST requests a URL.

I think you don't understand HTTP, perhaps you should read up
on it a bit.


use LWP::UserAgent;


Did you try reading the documentation for the module being used?

$response = $ua->get($base.$_);
^^^
^^^

Clearly a GET request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top