Passing Array Via CGI.pm

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Passing Array Via CGI.pm

    Hello all,

    I'm a Perl newbie here and have a quick question regarding CGI.pm.

    I have a CGI script that passes an array to another CGI script as
    follows:

    # sender.cgi
    .... (snipped code)
    my @fruit = ('apple','orange','pear');
    print $q->startform( -action=>'receiver.cgi' ),
    $q->submit( -name=>'Export Data' ),
    $q->hidden( -name=>'xlfruit' value='@fruit' ),
    $q->endform;
    .... (snipped code)

    # receiver.cgi
    .... (snipped code)
    my @fruit = param( 'xlfruit' );
    print @fruit\n;
    print @fruit[0]\n;
    .... (snipped code)

    The values of the fruit array pass through okay to the new CGI script
    but come as a single list. I.e. the out of print @fruit[0] is the
    whole line (apple orange pear) rather than just apple. It doesn't
    look like the variable is still an array after the pass. Is this
    normal or am I missing something?

    Thanks for any help.
    Tom
    shade Guest

  2. Similar Questions and Discussions

    1. Passing value to Array
      If I've got x = "test5" How can I put the value of x to Array list=; I'd try to use ---> list= but is not work.
    2. passing array in the url
      Hello there, I am unable to pass an array thought he url. Even the most simple array as in the code: $test = array(1,2,3,4); echo "<a...
    3. Array passing problem...
      Hoping someone can point out my more than likely simple mistake here... function getBranchArray($desig,$branchArray){ $arrayResult =...
    4. passing an array
      Hello, what is the best way to pass an array to a sub routine, IE. my @fields = qw(one two three); send_array(@fields);
    5. Passing a keyed Array via php.
      Hi ACteon! On 18 Aug 2003 19:17:23 -0700, acteon@yahoo.com (Acteon) wrote: Use - form method="post" - $_POST etc. - no books as they are...
  3. #2

    Default Re: Passing Array Via CGI.pm

    shade wrote:
    > # sender.cgi
    > ... (snipped code)
    > my @fruit = ('apple','orange','pear');
    > print $q->startform( -action=>'receiver.cgi' ),
    > $q->submit( -name=>'Export Data' ),
    > $q->hidden( -name=>'xlfruit' value='@fruit' ),
    the value should be '@fruit'? i'm sure you don't want that.
    i guess you want several hidden fields with the name 'xlfruit'.
    (you also forgot the comma and wrote = instead of => )
    try:
    map { $q->hidden( -name => 'xlfruit', value => $_ )} @fruit,

    then this:
    > my @fruit = param( 'xlfruit' );
    will work.

    hth, tina
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - the above mail address expires end of december 2003 -
    Tina Mueller Guest

  4. #3

    Default Re: Passing Array Via CGI.pm

    shade <shade@lore.cc> wrote:
    > I'm a Perl newbie here

    [url]http://mail.augustmail.com/~tadmc/clpmisc.shtml[/url]

    > $q->hidden( -name=>'xlfruit' value='@fruit' ),
    ^^^^ ^^

    Do not re-type Perl code

    Use copy/paste or your editor's "import" function rather than
    attempting to type in your code. If you make a typo you will get
    followups about your typos instead of about the question you are
    trying to get answered.


    Like this one.

    You are missing comma (,) and greater than (>) characters.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  5. #4

    Default Re: Passing Array Via CGI.pm

    Tad McClellan wrote:
    > shade wrote:
    (snipped)
    > You are missing comma (,) and greater than (>) characters.

    You have missed other problems which are clearly evident.


    Purl Gurl
    Purl Gurl Guest

  6. #5

    Default Re: Passing Array Via CGI.pm

    Purl Gurl wrote:
    > Tad McClellan wrote:
    > > shade wrote:
    (snipped)
    > > You are missing comma (,) and greater than (>) characters.
    > You have missed other problems which are clearly evident.

    "... (snipped code)"

    This is repeated four times in the originating article.


    Printed in part after corrections:

    <input type="hidden" name="xlfruit" value="@fruit" />


    This is not a problem of typographical errors as you and
    your alter ego, Tina, would have a reader believe.

    This is a problem of an ignorant troll trying to pass
    off a bunch of baloney based on a presumption readers
    are too stupid to take notice.

    It is clear to me you are also trying to pass off a
    bunch of baloney based on a presumption readers are
    too stupid to take notice, just as "Tina" has tried.


    Purl Gurl
    Purl Gurl Guest

  7. #6

    Default Re: Passing Array Via CGI.pm

    Purl Gurl <purlgurl@purlgurl.net> wrote:
    > Tad McClellan wrote:
    >> shade wrote:
    >
    > (snipped)
    >
    >> You are missing comma (,) and greater than (>) characters.
    >
    >
    > You have missed other problems which are clearly evident.

    No I didn't.

    I stopped reading the article as soon as I saw that the
    code presented could not be the real code. [1]

    If the OP can't be troubled to post the actual code they want
    to discuss, then I'll let somebody else help them, and move
    on to helping one of the more conscientious posters.




    [1] many people will do that silently, which is why the Posting
    Guidelines suggest you avoid it. :-)

    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  8. #7

    Default Re: Passing Array Via CGI.pm

    Tad McClellan wrote:
    > Purl Gurl wrote:
    > > Tad McClellan wrote:
    > >> shade wrote:
    (snipped)
    > >> You are missing comma (,) and greater than (>) characters.
    > > You have missed other problems which are clearly evident.
    > No I didn't.
    > I stopped reading the article as soon as I saw that the
    > code presented could not be the real code.

    By your own admission you read the problems you missed,
    and by your own admission you read four clear indicators
    there are no typographical errors, as you claim.

    You have forgotten you have me killfiled.

    I don't care much for baloney.


    Purl Gurl
    Purl Gurl Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139