more useful options | |
PerlMonks |
Parsing by indentationby llarochelle (Beadle) |
on Oct 24, 2018 at 18:18 UTC ( [id://1224600]=perlquestion: print w/replies, xml ) | Need Help?? |
llarochelle has asked for the wisdom of the Perl Monks concerning the following question: I've been trying to create a config file parser to parse Cisco IOS configs and such. The final objective would be to show relevant data in contexts based on filters in a configuration file. For example, with such a config file it would display all interfaces where we've found the line "access vlan" as a child of the "interface" context and only show lines containing "speed", "duplex" and "description".
So far, so good. I read the "running-config" and I index the lines depth (given that a non-empty line , not beginning with a space (\s) has a depth of 0) in an array. Then, in another read I use that index to read the data again, this time using relative position based on depth to create the "childs" of a context. Here's the function :
Using this sub, I can return a hash, then based on the presence of an arrayref for a given key, apply filters as explained. This works pretty well, so far very proud of this piece of code. Problem comes when I want to find childs of childs. In the example below, the childs of "given param2" would reprensent my next challenge.
So after thinking about this for a while and failing with different approaches, my question comes in 2 separate parts : 1) Is there a better way to do this that I'm not seeing ? 2) How could I keep tagging childs of childs as the lines dig deeper and identify them properly in a data structure ? Thank you for reading up to this line :)
Back to
Seekers of Perl Wisdom
|
|