Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Nothing special. Isn't that what Perls all about?

by btrott (Parson)
on May 24, 2001 at 00:45 UTC ( [id://82726]=note: print w/replies, xml ) Need Help??


in reply to Nothing special. Isn't that what Perls all about?

I'm no regex whiz, but I think you're making Perl do a lot of extra work with that regex to match table rows. All of those dot-stars means a lot of backtracking, I think.

Anyway, here's a slightly modified version:

use LWP::Simple; my $user = shift or die "usage: $0 <username>"; $_ = get "http://www.efd.lth.se/loginload.shtml" or die "Cannot get!\n"; my $re = '<TR ALIGN=center>' . ('<TD>\s*([^<]+)</TD>' x 6) . '</TR +>'; my($load, $host); while (/$re/g) { $host = $1, $load = $5 if !defined $load || $5 < $load; } print "Host $host has load of $load\n"; exec("ssh $user\@$host.efd.lth.se") or die "Can't exec ssh: $!";
Note also that I took out the exit after the exec--you don't need that, because exec never returns.

I think my regex might be a little more friendly, but I'm not absolutely sure. Note also that any regex solution will be less robust and less succeptible to HTML formatting changes than a solution like merlyn's.

Updated to test return value from exec, because I should've been more clear about exec and the possibility that it could return.

Replies are listed 'Best First'.
Re: Re: Nothing special. Isn't that what Perls all about?
by Anonymous Monk on May 24, 2001 at 01:21 UTC
    exec returns if the program to be execed is not there.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://82726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-25 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found