The immediate problem is syntax. $items2show_ref is a reference so you need to dereference it. It's referencing an array so you need $items2show_ref->[ARRAYX] to get at an element of the array. Often the array element will be a reference too so you need to dereference that. If the element references an array you can @{$items2show_ref->[ARRAYX]} to work with the referenced array or $items2show_ref->[ARRAYX][$element] to get at an element.

I'd use a hash instead of an array or, even better, use light weight OO. Using a hash there is a small change from $items2show[kArrayX] to $items2show{ArrayX} with the advantage that you don't need to generate the constant (and the disadvantage that you get run time rather than compile time errors for typos).

Using light weight OO you could use the same access techniques as you do for either a hash or an array, or you could provide methods for wrapping up tricky stuff:

my $obj = bless {}; $obj->checkForm (...); $obj->showPage (...); sub checkForm { my ($self, @params) = @_; ... $self->addArrayXValue ($value); ... } sub showPage { my ($self, @params) = @_; my $value = $self->getArrayXValue (-1); ... } sub addArrayXValue { my ($self, $value) = @_; push @{$self->{arrayX}}, $value; } sub getArrayXValue { my ($self, $index) = @_; return $self->{arrayX}[$index]; }

Perl's payment curve coincides with its learning curve.

In reply to Re: getting in trouble avoiding global variables by GrandFather
in thread getting in trouble avoiding global variables by cmac

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.