in reply to Is there a better way to approach this?
You shouldn't declare those variables here but inside the for loop.
my @ospf2database = @_;You should declare $line and $dl here:
for my $line (@ospf2database) {Why chomp $line when you are just appending a newline again anyway?
if ($line =~ /^Router/) { $dl = 1; }Do you need two steps? Can't you just do the push in the if block? You are testing $line three times although if it matches /^Router/ it will never match /^Network/ or /^Extern/.
}if ( $line =~ /^Router/ ) { push @router, "$line\n" } elsif ( $line =~ /^Network/ ) { push @network, "$line\n" } elsif ( $line =~ /^Extern/ ) { push @external, "$line\n" }
|
|---|