http://qs321.pair.com?node_id=82726


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.