I'm converting a mod-perl2 module from having lots of global variables to having just read-only globals, with an eye toward maybe running it under a threaded Apache MPM in the future. The 'handler' calls a subroutine 'checkForm', which fills an array with various data that it wants to pass to a subroutine 'showPage' that the handler calls later. This array is declared in the handler, and is passed by reference to checkForm and showPage:
sub handler { my @items2show; ... checkForm (..., \@items2show); ... showPage (..., \@items2show); ... }
Items in @items2show are identified by a set of global subscript constants near the start of the script, one of which might be
use constant ARRAYX => 3;
One of the things that checkForm wants to pass to showPage in @items2show is an array that's anonymous other than being passed by reference as items2show[ARRAYX]. Near the start of checkForm the overall items2show array is initialized. Later in checkForm, value(s) want to be pushed onto the ARRAYX array.
sub checkForm { my (..., $items2show_ref) = @_; @$items2show_ref = (); $$items2show_ref[ARRAYX] = []; # should this be () ?? ... push @??ARRAYX??, $value; ... }
I've tried various syntaxes in the push statement above, and cannot get Perl to accept any of them. Also I'm not clear on whether the initializer for the ARRAYX array wants to be [] or (), although this can be worked thru if I can get the push syntax right...

Summarizing:
Q1: push WHAT?
Q2: [ ] or () ?

Of course if there's a better way to do the whole thing, I'm all ears...
Thanks for being there,
cmac

In reply to 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.