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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.