I'm trying to pass an array, then fetch it using $cgi->param(). I can pass text and other scalars, but not arrays. Can someone please tell me what I'm doing wrong here, and how to fix it?
#!/usr/local/bin/perl -w use strict ; use English ; use Socket ; use CGI qw/:all/ ; my($rec) ; my(@Record) ; my($cgi) ; my(%Hash) ; my($String) ; my($item) ; $cgi = new CGI ; # # See if there were passed values from the input form # if ( $cgi->param('string') ) {$String = $cgi->param('string') ;}; if ( $cgi->param('array') ) {@Record = $cgi->param('array') ;}; # If string has a value, then do the following. If not, # present the input form. if ( $String ) { Header() ; print "The String is: $String<br>\n" ; print "The Array has in it:<br>\n" ; foreach ( @Record ) { print "File: $_->{file}\n" ; print "Item: $_->{item}\n" ; } ; print "We're done.....\n" ; closeHTML() ; # This is the input form....... } else { # Load up the array with some stuff.... $rec->{'file'} = "/usr/local/bin/myfile" ; $rec->{'item'} = "type: file" ; push ( @Record, $rec ) ; $rec->{'file'} = "/usr/local/bin/ourfile" ; $rec->{'item'} = "type: file" ; push ( @Record, $rec ) ; Header(); print "<FORM ACTION=\"/cgi-bin/test_ray.cgi\" METHOD=\"POST\" " ; print " enctype=\"multipart/form-data\" " ; print "<P><B>Enter a string in this box:</b>" ; print "<BR><INPUT TYPE=TEXT NAME=\"string\" "; print "VALUE=\"$String\" SIZE=15>\n" ; print hidden('array', @Record) ; print "<INPUT TYPE=SUBMIT VALUE=\"Submit Request\"> " ; print "<INPUT TYPE=RESET VALUE=\"Reset Form\"></form>\n" ; closeHTML(); } ; ############### HTML Header ################### sub Header { print "content-type: text/html\n\n" ; print "<html>\n" ; print "<head>\n" ; print "<title>Pass the array</title>\n" ; print "</head>\n" ; print "<h1>\n" ; print "Array:\n" ; print "</h1>\n" ; print "<body bgcolor=white>\n" ; print "<font color=black>\n" ; } ; ################# close HTML ################## sub closeHTML { print "</font>\n" ; print "</body>\n" ; print "</html>"; } ;
thanks, andy t.

In reply to passing/retrieving arrays by andy_t

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.