wa4otj has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Novice flails arrays
by kvale (Monsignor) on Mar 26, 2004 at 21:44 UTC | |
by wa4otj (Beadle) on Mar 26, 2004 at 22:04 UTC | |
|
Re: Novice flails arrays
by dragonchild (Archbishop) on Mar 27, 2004 at 01:53 UTC | |
|
Re: Novice flails arrays
by davido (Cardinal) on Mar 27, 2004 at 06:53 UTC |