|Just another Perl shrine|
Aid for Parse::RecDescent-er(s)by hsmyers (Canon)
|on Jun 24, 2002 at 01:42 UTC||Need Help??|
I've recently been involved with a 'small language' project using (of course) Parse::RecDescent and while thrashing about developed a tool that has made my life a good deal simpler. Perhaps by extension it could be useful to others as well.
Which if you run produces:
The first portion is obviously the output of the call to Dumper and should present no particular mystery to any one familiar with that excellent module. The second portion however strangely formatted it may appear is my own concoction. You will note that it is centered within an 80 column format. Why?--because it grows from either side depending on depth of the data structure. Next, the material on the right hand side obviously is the same as what you would receive from Dumper--although formatted in a fashion that makes alignment of array indicators a bit more legible. This leaves the odd arrangement of numbers on the left hand side. These are in fact, the indices of the array displayed. For instance consider the following list:
The chief value of this function comes when you begin to process portions of the tree and need to easily see just what it was that got passed to you! It doesn't take much work with parse trees to notice that they quickly grow to a very large size--often too large to easily keep track of. And even if printed, usually too large to deal with that way as well. After doing more work with 'print' this that and the other thing than perhaps I should admit to, I finally came apon this approach! I suppose that you might think of it as having the virture of the Dumper approach as a map, with the added benefit clearly marked labels. Come to think of it, there is no particular reason that this couldn't be usful where ever you need to know just how to get your hands on a particular 'thing' buried within a typical perl data structure!
Happy data mining...
–hsm"Never try to teach a pig to sing…it wastes your time and it annoys the pig."
Edited: ~Wed Jul 3 17:39:28 2002 (GMT),