Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Split file output into array of arrays

by GrandFather (Saint)
on Feb 16, 2010 at 23:31 UTC ( [id://823575]=note: print w/replies, xml ) Need Help??


in reply to Split file output into array of arrays

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", ], ]

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Split file output into array of arrays
by spickles (Scribe) on Feb 16, 2010 at 23:49 UTC

    Thank you!! So to access each array, it would be

    $records[0][0]<br/> $records[0][1]<br/> $records[0][2]<br/> $records[1][0]<br/> $records[1][1]<br/> $records[1][2]<br/> . . .

    The reason I ask is that each array created and pushed to @records is not explicitly named.

    Regards,
    Scott

      You asked for an array of arrays. If you wanted an array of hashes or something else you should have said so. Maybe your sub that performs the matching can sort it out? Of course I can't see that code so it's not clear where or what your current problem is.


      True laziness is hard work

        GrandFather -

        No worries there. I asked for an array of arrays, and that's what you gave me. I was just wanting to clarify that the method of accessing them would be as I posted earlier

        $records[firstarray][firstrecord] $records[secondarray][firstrecord] . .

        I'll work on sorting it out and post back if I have problems.

        Regards,
        Scott

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://823575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2025-07-15 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.