in reply to Re^2: Cable modem status
in thread Cable modem status

well, the conventional wisdom is use a module to parse HTML and I was tempted to make that comment first time around. However the regex seemed sufficiently trivial that it didn't seem really to matter. Using something like HTML::TreeBuilder would sure make it easier to dig the data out for a lot of modems though - mine (which uses a table) for a start!

If you are going to use /x then take advantage of it and use some white space to break up the different components of the regex so they are easier to parse by eye. Consider:

$content =~ m{ Frequency(\d+\s Hz)\s Signal \s To \s Noise \s Ratio([\d.]+ \s dB)\s Power \s Level([\d.-]+ \s dBmV) }xi or My_Die('content failed!');

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: Cable modem status
by ruzam (Curate) on Feb 17, 2007 at 03:46 UTC
    Ah, that's the ticket! Much easier on the eyes. Thanks for the suggestion.

    I wanted to keep it light weight and avoid bringing in any more modules than necessary (right or wrong, that's just my way). The Motorola uses tables to display the data as well which is why I sucked off the row/column tags (s!</?t[dr]>!!g). As it turns out the page generated by the modem isn't 'correct' html anyway. The last row on the 'Signal' page ends with a <tr> instead of a </tr> which prompted me to simply snuff the tags in the first place. I suspect other modems that do this are similarily 'simplistic and possibly incorrect' in their web page designs.

    Speaking of other modems, the other service provider in my area is the telephone company (it's a two horse town when it comes to local internet). I'm currently tracking down the make and model of the Telco's latest offering to see what possiblities lie there. On the one hand it would be nice to have one script do it all, but on the other, for what little code there actually is, it probably doesn't make much sense bloat it out for generic modem types.