Monks,
I have a script to parse sections of a configuration file using a single foreach loop. This loop performs many matches in two 2 tiers. I want parent tier matches to send the following lines to functions until "!" is matched.
------- Sample Text -------
!
interface Ethernet
blah...
blah...
!
interface Gigabit
blah...
blah...
!
interface Ethernet
blah...
!
------- Sample Text -------
I envisioned this to work something like this, but feel this is not the best way to achieve this. For one, in my match statements for "Ethernet" and "Gigabit", I don't know how to advance $line forward to see if we have reached a "!". Could anyone please recommend an approach for something like this. Thanks in advance!
foreach $line (@cfg) {
if ($line =~ m/^interface (\.*)/) {
if ($1 eq "Ethernet") {
&parse_ethernet($1);
Keep parsing until $line matches "!"
}
if ($1 eq "Gigabit") {
&parse_gigabit($1);
Keep parsing until $line matches "!"
}
}
if ($line =~ m/^system (\.*)/) {
blah...
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.