felwick has asked for the wisdom of the Perl Monks concerning the following question:

last nights' code help worked beautifully...
my @array = ("AOL", "Yahoo", "Ask Jeeves/Ask.com", "Alltheweb", "Alta +Vista", "Lycos", "iWon", "Teoma", "Wisenut", "MSN", "Netscape", "Info +space", "Looksmart"); shuffle(@array); my ($comp1, $comp2, $comp3, $comp4, $comp5) = @array[0..4]; print qq~ <input type="hidden" name="comp1" value="$comp1"> <input type="hidden" name="comp2" value="$comp2"> <input type="hidden" name="comp3" value="$comp3"> <input type="hidden" name="comp4" value="$comp4"> <input type="hidden" name="comp5" value="$comp5"> ~;
in the next sub however, instead of hardcoding the @array values, i need to get the value of 15 form elements. when i use the following:

my @array= param('aware02', 'aware03', 'aware04', 'aware05', 'aware06' +, 'aware07', 'aware08', 'aware09', 'aware10', 'aware11', 'aware12', ' +aware13', 'aware14');
i get the param name - not the value. what am i doing wrong?!

thanks again...

felwick

Replies are listed 'Best First'.
Re: random array - a newer twist
by Zaxo (Archbishop) on Nov 05, 2002 at 22:39 UTC

    You are misusing &CGI::param. I believe your usage sets the value of the 'aware02' field to an array of the remaining arguments and returns that array to @array.

    Here's how to do what you want:

    my @array= map {[param($_)]} ( 'aware02', 'aware03', 'aware04', 'aware05', 'aware06', 'aware07', 'aware08', 'aware09', 'aware10', 'aware11', 'aware12', 'aware13', 'aware14');

    The square brackets are in the map block to take care of any multiple valued fields. You'll need to dereference the array elements to get their values.

    After Compline,
    Zaxo

      zaxo - thanks for the quick response....i'm new to CGIpm and have been coding since about 7pm last nite - aka, i'm braindead right now.

      what i'm getting back now is

      <input type="hidden" name="comp1" value="ARRAY(0x102392d4)"> <input type="hidden" name="comp2" value="ARRAY(0x10239388)"> <input type="hidden" name="comp3" value="ARRAY(0x102392ec)"> <input type="hidden" name="comp4" value="ARRAY(0x10237080)"> <input type="hidden" name="comp5" value="ARRAY(0x1023931c)">
      how do i make this mean something?

      thanks, felwick

        That's what I was talking about with 'dereferencing'. Either leave out the square brackets in the map block (if there are no multivalued fields) or else wrap the values you print in '@{}' to dereference them. The References quick reference tutorial by tye may help you a lot.

        You may want to think of other data structures to use. A hash of values keyed by field names is often natural for cgi form data.

        After Compline,
        Zaxo