I've posted an extended example that processes multiple Networks per file below, but you may not understand how it works, and may therefore hove problems adapting it for your real program.

Given your current level of Perl skill, I think that you are more likely to understand one of the other solutions presented in this thread, particularly grandfather's with which you have already had extensive help. I think that you should probably get yourself a good Perl book and take the time to play with a few small programs of your own before attempting more complicated tasks.

#! perl -slw use strict; my( $nName, $iName, $vrid, $state, $paddr, $nAddr, $oAddrs, @oAddrs ); die "File does not contain a Network name header" unless ( $nName ) = <DATA> =~ m[Network\sname \s+ (\S+)]x; local $/ = "\nI"; while( <DATA> ) { if( ( $iName, $vrid, $state, $paddr, $nAddr, $oAddrs ) = m[ (?=.*? nterface \s+ (\S+) ) (?=.*? VRID \s+ (\S+) ) (?=.*? State: \s+ (\S+) ) (?=.*? Primary\saddress: \s+ (\S+) ) (?=.*? Number\saddresses: \s+ (\S+) ( .+? ) (?=Monitored\scircuits:) ) ]smx ) { @oAddrs = split ' ', $oAddrs; print join ', ', $nName, $iName, $vrid, $state, $paddr, $nAddr +, @oAddrs; ### This is the new code that allows it to process ### multiple networks within the same file. ### If the last interface record we read has a Network record ### appended to the end, then parse out and update the $nName +variable. $nName = $1 if m[Network\sname \s+ (\S+) \s* \nI$]x; ### If you do not understand how this works, then you should t +ry adding ### some print statements and play with this test script until + you do understand. } else { warn "File did not match required format"; } } __DATA__ Network name A Interface WEB_A ggggggggg VRID 145 State: Master XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 194.551.205.250 Number addresses: 1 135.51.045.242 Monitored circuits: vbgghdfgdfg Interface WEB_B ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 2 135.51.05.22 321.654.987.111 Monitored circuits: vbgghdfgdfg Interface WEB_C ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 3 135.51.05.22 123.456.789.001 321.654.987.111 Monitored circuits: vbgghdfgdfg Network name B Interface WEB_A ggggggggg VRID 145 State: Master XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 194.551.205.250 Number addresses: 1 135.51.045.242 Monitored circuits: vbgghdfgdfg Interface WEB_B ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 2 135.51.05.22 321.654.987.111 Monitored circuits: vbgghdfgdfg Interface WEB_C ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 3 135.51.05.22 123.456.789.001 321.654.987.111 Monitored circuits: vbgghdfgdfg

produces

C:\test>junk1 A, WEB_A, 145, Master, 194.551.205.250, 1, 135.51.045.242 A, WEB_B, 145, backup, 19.51.205.20, 2, 135.51.05.22, 321.654.987.111 A, WEB_C, 145, backup, 19.51.205.20, 3, 135.51.05.22, 123.456.789.001, + 321.654.987.111 B, WEB_A, 145, Master, 194.551.205.250, 1, 135.51.045.242 B, WEB_B, 145, backup, 19.51.205.20, 2, 135.51.05.22, 321.654.987.111 B, WEB_C, 145, backup, 19.51.205.20, 3, 135.51.05.22, 123.456.789.001, + 321.654.987.111

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: just another search program by BrowserUk
in thread just another search program by sunny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.