Keep It Simple, Stupid | |
PerlMonks |
Split file output into array of arraysby spickles (Scribe) |
on Feb 16, 2010 at 23:19 UTC ( [id://823574]=perlquestion: print w/replies, xml ) | Need Help?? |
spickles has asked for the wisdom of the Perl Monks concerning the following question: Hello Monks. I'm trying to think of the best way to parse an output file from a Cisco router that shows me the other Cisco devices it knows about. The output separates records using a string of hyphens. I can't think of a way to parse that file and pull the multiple lines of each record out into an array? I've tried for loops, while loops, next unless, etc. But I'm still struggling to figure out the best way to loop through this file line by line and put each set of lines that make up a device record into its own array. I would like to create an AoA so that I can then parse each device record, matching lines by keywords and storing them to their own hash, which I then write to a CSV file. I have working code that can parse the file line by line performing a loop and matching lines. I thought each record was 20 lines in length, so I stepped through the output file 20 lines at a time and sent those lines to a subroutine to perform the matching. The problems is that not all records are 20 lines in length (some are 21) and it throws it off. I wouldn't think code posting is required, since I have nothing working for the parsing of the file. But I can post parts of the code if someone requests it. What I will post is the first couple of records of the output file:
So you can see that records are bounded by the hyphens. If I can find a way to pull each set of multiple lines out into its own array, I'll be all set. So basically use the hyphens to indicate that a new record has begun, and until you reach the next set of hyphens, put all the lines in between into a separate array. Regards,
Back to
Seekers of Perl Wisdom
|
|