in reply to Wrong regex?

#!/usr/local/bin/perl use strict; use warnings; print "IP\t\tStatus\n"; print "-" x 25; print "\n"; while(<DATA>){ chomp; next unless $_ =~ /^<\/HEAD>.*/i; #skip un-interestin +g lines. #my ($ip, $status) = $_=~ m/(\d+\.\d+\.\d+\.\d+)\s+:\s+( +\w+)/; my ($ip, $status) = $_=~ m/([0-9\.]+)\s+:\s+(\w+)/; print "$ip\t $status\n"; } __DATA__ </HEAD><BODY><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"><H2>Set Node + to Monitored <BR> 10.10.10.10 : Minor </H2><FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded"> </HEAD><BODY><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"><H2>Set Node + to Monitored <BR> 10.10.10.9 : Major </H2><FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded"> </HEAD><BODY><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"><H2>Set Node + to Monitored <BR> 10.10.10.1 : Major </H2><FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
#OUTPUT:
IP Status ------------------------- 10.10.10.10 Minor 10.10.10.9 Major 10.10.10.1 Major


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re^2: Wrong regex?
by graff (Chancellor) on Feb 10, 2010 at 18:28 UTC
    Why would you assume that an input line would be "un-interesting" if it doesn't start with </HEAD>.* ? And why did you think you need ".*" in that regex?