in reply to Re^2: just another search program
in thread just another search program
Perhaps if I explain how the code works you can adapt it to your actual data? Here's the main part of code again:
my $lastIP; while (<DATA>) { print if /network name|interface name|VRID|state|primary address/i; print "$lastIP\n\n" if /Monitored circuits:/ and defined $lastIP; $lastIP = $1 if /((\d{1,3}\.){3}\d{1,3})/; }
$lastIP remembers the last IP address seen so it can be printed when "Monitored circuits" is noticed.
while (<DATA>) reads the data one line at a time. You would normally use a file handled that you had created with open inFile, '<', 'filename' in place of DATA.
print without parameters prints the contents of the default variable - in this case the data line that was last read from DATA. if /network name|i...address/i matches an interesting line (insensitive to case) and allows the print if there is a match.
print "$lastIP\n\n" prints the IP address preceeding the line containing "Monitored circuits".
This most important line is the one that matches "interesting lines". It does that by matching any of "network name", "interface name", "VRID", "state" or "primary address". Note the | between each string in the regular experssion pattern. They allow a match on any of the strings in the pattern.
You should be able to take that and extend the match to do what you require. If not, show us your attempt, what it prints, and what you would like it to print. Note that we only need pertinant data and only enough to demonstrate the problem. Otherwise the problem gets burried in clutter. Reduce your data to a bare minimum the shows the issue.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: just another search program
by sunny (Initiate) on Feb 14, 2006 at 08:18 UTC | |
by GrandFather (Saint) on Feb 14, 2006 at 10:20 UTC | |
by sunny (Initiate) on Feb 14, 2006 at 14:56 UTC | |
|
Re^4: just another search program
by sunny (Initiate) on Feb 15, 2006 at 12:59 UTC |