Accessing all CGI input parameters via loop ?

Discussion in 'Perl Misc' started by - Bob -, Mar 23, 2007.

  1. - Bob -

    - Bob - Guest

    Perl newbie question:

    I need a little loop that will let me access all of the input
    parameters from an HTML form in a generic way without knowledge of the
    specific variable (html form field) names.

    I know how to do this: my $name = (param("name"));

    But, when I don't know the field names, how do I access the structure
    of the param's with an index or other non-field-specific technique?

    Code snippet appreciated, like I said "newbie" :)

    Thanks,
    - Bob -, Mar 23, 2007
    #1
    1. Advertising

  2. - Bob -

    Paul Lalli Guest

    On Mar 23, 8:03 am, - Bob - <> wrote:
    > Perl newbie question:
    >
    > I need a little loop that will let me access all of the input
    > parameters from an HTML form in a generic way without knowledge of the
    > specific variable (html form field) names.
    >
    > I know how to do this: my $name = (param("name"));
    >
    > But, when I don't know the field names, how do I access the structure
    > of the param's with an index or other non-field-specific technique?
    >
    > Code snippet appreciated, like I said "newbie" :)


    You don't need a loop for this. But if you really wanted to:
    my %value_of;
    for my $input (param()) {
    $value_of{$input} = param($input);
    }

    Like I said, you don't need the loop for this, because CGI.pm comes
    with a way to generate this hash:

    my $value_of_ref = Vars();

    Or you could even just import them all into a bunch of package
    variables:

    import_names('R');
    print "$R::name, $R::value, $R::age\n"; #etc

    Have another read of
    perldoc CGI
    There are a lot of options that you may not be aware of yet.

    Paul Lalli
    Paul Lalli, Mar 23, 2007
    #2
    1. Advertising

  3. - Bob -

    - Bob - Guest

    On 23 Mar 2007 06:34:12 -0700, "Paul Lalli" <> wrote:


    >You don't need a loop for this.


    I still have a more traditional programming mindset :)

    >But if you really wanted to:
    >my %value_of;
    >for my $input (param()) {
    > $value_of{$input} = param($input);
    >}


    Thanks, that got me started.

    >Have another read of
    >perldoc CGI
    >There are a lot of options that you may not be aware of yet.


    Will do... thanks for the jumpstart.
    - Bob -, Mar 23, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LarsenMTL
    Replies:
    4
    Views:
    655
    Eric Walstad
    Nov 4, 2004
  2. Anshu
    Replies:
    5
    Views:
    379
    Howard
    Aug 14, 2006
  3. D
    Replies:
    3
    Views:
    241
  4. john.swilting
    Replies:
    0
    Views:
    93
    john.swilting
    Mar 21, 2007
  5. Isaac Won
    Replies:
    9
    Views:
    352
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page