in reply to Trying to split a file into array conditionally
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
|
|---|