What is going on?

Discussion in 'Perl Misc' started by giraffe6044@gmail.com, Apr 15, 2005.

  1. Guest

    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;
    }
    , Apr 15, 2005
    #1
    1. Advertising

  2. <> wrote:


    > 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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    1
    Views:
    584
    VB Programmer
    Jul 10, 2003
  2. Navin
    Replies:
    3
    Views:
    642
    Navin
    Jul 28, 2003
  3. Paul

    I am going to kill mysql

    Paul, Aug 4, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,627
    Kevin Spencer
    Aug 5, 2003
  4. Kathy Burke
    Replies:
    6
    Views:
    620
    Munsifali Rashid
    Aug 13, 2003
  5. Jay Douglas
    Replies:
    0
    Views:
    399
    Jay Douglas
    Aug 28, 2003
Loading...

Share This Page