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...
}
}