Ah, the Push down automata, I knew it would return to haunt me someday. Applied theory with Professor Decker...how I miss it q-;
Thanks for this very helpful info John. Actually, my previous solution was on a similar track but instead of implementing a stack to push and pop I was doing something more hackish and just using a variable that would increment for each
{ and decrement for each
} and return the brace that brought the var back to zero. This was a very hackish approach to the problem, and your stack suggestion has obvious advantages aside from its more poetic approach.
I'll take a look at Parse::YAPP, sounds like a useful read. Aside from the fact that (??{}) sequence makes the regex code more compact than implementing a stack, are there advantages or disadvantages in terms of runtime, memory, etc? I guess what I'm asking is, if you had perl 5.7 running on your machine and a rainy afternoon to spend writing the best code you could, which technique would you choose? I am very interested in making my code the best it can be, since I hope others will find it useful and want to use it as well. Gotta work on my skills before that hallowed day, though.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.