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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|