For a slightly different way to do it that is maybe more maintainable you could:
use strict; use warnings; my @lines = <DATA>; my @records = ospf2_split_database (@lines); print @$_ for @records; sub ospf2_split_database { my @ospf2database = @_; my %data = (Router => [], Network => [], Extern => []); my $keys = join '|', keys %data; my $array; for my $line (@ospf2database) { $array = $data{$1} if $line =~ /^($keys)/; next unless defined $array; push @$array, $line; } return values %data; } __DATA__ Heading stuff that should be ignored Router: 1st router line 2nd router line this router line includes keys Network and Extern Network: 1st network record Extern: 1st extern record Extern: 2nd extern record Router: 2nd router record
Prints:
Network: 1st network record Router: 1st router line 2nd router line this router line includes keys Network and Extern Router: 2nd router record Extern: 1st extern record Extern: 2nd extern record
In reply to Re: Is there a better way to approach this?
by GrandFather
in thread Is there a better way to approach this?
by ewhitt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |