|XP is just a number|
quickly create reference to boring hash.by tford (Beadle)
|on May 13, 2008 at 21:58 UTC||Need Help??|
tford has asked for the
wisdom of the Perl Monks concerning the following question:
I'm working on lexing mathematical expressions and I'm constructing a toy example of a non-deterministic finite automaton.
I've decided that the transition tables should be stored in hashes so that input characters can actually serve as keys to the hash. It is possible that some inputs may map to more than one transition, so I've also decided that each key (input character) should have a reference to an anonymous array as its value. If the input character only specifies one transition, then the value should be a reference to an array containing only one element!
This way of thinking produces some states with pretty boring transition tables. For example, a state that represents the situation of "about to read an identifier," which I've called 'id_0', might have a transition table which looks like the following.
Now, in my toy example, I've constructed this state using the following technique.
My question is, "Is there a way to do this without the intermediate %hash variable?"
Any help will be appreciated, whether it's a "Here's how you do it" one liner, or a "Why do you want to it that way, when you could do it this way" type of thing.