I wrote this function and it does what I need. I was wondering if there was a more Perl'ish way to approach it? Basically, the function looks for certain headings (e.g. Router, Network, and Extern) and adds the following lines into a specific array, until a new heading is found.
sub ospf2_split_database {
my ($dl, $line) = "";
my @ospf2database = @_;
my (@router, @network, @external) = ();
for $line (@ospf2database) {
chomp($line);
if ($line =~ /^Router/) { $dl = 1; }
if ($line =~ /^Network/) { $dl = 2; }
if ($line =~ /^Extern/) { $dl = 5; }
switch ($dl) {
case 1 { push(@router, "$line\n"); }
case 2 { push(@network, "$line\n"); }
case 5 { push(@external, "$line\n"); }
}
}
return(\@router,\@network,\@external);
}
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.