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]; }
In reply to Re: getting in trouble avoiding global variables
by GrandFather
in thread getting in trouble avoiding global variables
by cmac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |