Instead of reading a 'line' at a time read a 'record' at a time. Set $/ to the record separator ("-------------------------\n" in this case) and away you go:
use strict; use warnings; use Data::Dump; local $/ = "-------------------------\n"; my @records; while (<DATA>) { chomp; next unless length; push @records, [split "\n"]; } print Data::Dump::dump (\@records); __DATA__
Given the data supplied by the OP prints:
[ [ "Device ID: HS-IDF3-C3550-A.B.org", "Entry address(es):", " IP address: 10.x.x.x", "Platform: Cisco WS-C3550-12G, Capabilities: Router Switch IGMP", "Interface: GigabitEthernet3/1, Port ID (outgoing port): GigabitE +thernet0/2", "Holdtime : 158 sec", "", "Version :", "Cisco IOS Software, C3550 Software (C3550-IPSERVICES-M), Version +12.2(25)SEE, RELEASE SOFTWARE (fc2)", "Copyright (c) 1986-2006 by Cisco Systems, Inc.", "Compiled Thu 02-Feb-06 20:37 by antonino", "", "advertisement version: 2", "Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27 +, value=00000000FFFFFFFF010221FF0000000000000005313DD680FF0000", "VTP Management Domain: ''", "Duplex: full", "Management address(es):", " IP address: 10.x.x.x", ], [ "Device ID: HS-IDF3-C3550-A.B.org", "Entry address(es):", " IP address: 10.x.x.x", "Platform: Cisco WS-C3550-12G, Capabilities: Router Switch IGMP", "Interface: GigabitEthernet2/1, Port ID (outgoing port): GigabitE +thernet0/1", "Holdtime : 138 sec", "", "Version :", "Cisco IOS Software, C3550 Software (C3550-IPSERVICES-M), Version +12.2(25)SEE, RELEASE SOFTWARE (fc2)", "Copyright (c) 1986-2006 by Cisco Systems, Inc.", "Compiled Thu 02-Feb-06 20:37 by antonino", "", "advertisement version: 2", "Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27 +, value=00000000FFFFFFFF010221FF0000000000000005313DD680FF0000", "VTP Management Domain: ''", "Duplex: full", "Management address(es):", " IP address: 10.x.x.x", ], ]
In reply to Re: Split file output into array of arrays
by GrandFather
in thread Split file output into array of arrays
by spickles
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |