From your question, it appears to me that you want to solve the "make all entries single strings" problem. I would key on the phrase "directly connected", that is already a single line record. The two line records don't have that phrase in the first line and have "via" in the second line.
So, the places below where there is a "push", the route record is "complete" meaning there is now a single string routing record.
What you want to do past that is unclear to me. Perhaps you could explain further what info you want to extract now that you can get these records into single string entries.
#!/usr/bin/perl -w
use strict;
my @routes;
my $temp='';
while(<DATA>)
{
next if /^\s*$/; #skip blank lines
chomp;
if (/directly connected/)
{
push @routes, $_;
next;
}
if (/via/)
{
push @routes, "$temp$_";
$temp='';
next;
}
$temp .= $_;
}
print join("\n",@routes),"\n";
__DATA__
C AAA.BBB.CCC.DDD 255.255.255.224 is directly connected, INTERFACENAME
O E1 WWW.XXX.YYY.ZZZ 255.255.224.0
110/112 via AAA.BBB.DDD.EEE, 696:56:46, INTERFACENAME
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.