sub ospf2_split_database {

    my ($dl, $line) = "";

You shouldn't declare those variables here but inside the for loop.

    my @ospf2database = @_;
    my (@router, @network, @external) = ();

    for $line (@ospf2database) {

You should declare $line and $dl here:

    for my $line (@ospf2database) {
        my $dl;

        chomp($line);

Why chomp $line when you are just appending a newline again anyway?

        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"); }

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" }
        }
    }
    return(\@router,\@network,\@external);
}


In reply to Re: Is there a better way to approach this? by jwkrahn
in thread Is there a better way to approach this? by ewhitt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.