I am trying to improve my mind and find a more creative solution to a programming problem. I appeal to the Monks for enlightenment.
I am writing an interface between a low-level PIC controlled device and a high-level voice response system. The serial interface to the PIC was easy, and I can get data in and out of the the VR system.
For the purposes of recursion I create a list of "Zones", like this:
@Zonelist = ("@WGLZAL","@WGLZAU","@WGLZBL","@WGLZBU", "@WGLZCL","@WGLZCU","@WGLZDL","@WGLZDU");
This works well enough for a few zones. But I need to expand this significantly. Increasing the length of this definition seems an ugly and inefficent way to do it.
Each array contains three elements, a text name and two boolean values represented as text strings i.e. @WGLZGL = ("WGLZGL","TRUE", "FALSE");.
The Zone names are predictable, named A-P, upper and Lower. The 'WGL' is more-or-less meaningless, serving only to relate the variables together in the mind of the programmer.
It really seems that it should be practical to recurse thru the alphabet and create the Zonelist dynamically. But I haven't figured out an efficient way to do this.
It also seems I should be able to eliminate the text name since it is the same as the array name. I need to be able to use the name as a string value in several places later. Perhaps I need a painless way to extract the array name as a string to use. Here is one example of how it is used.
foreach $zone (@Zonelist) { @cmmd = split(/ /,$zone); print "Updating Flag @cmmd[0] from @cmmd[1]to @cmmd[2]"; }
Can the Perl Monks enlighten me?
Nathan
In reply to Novice flails arrays by wa4otj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |