Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass an array to a perl cgi script with a HTML form?

Tags:

cgi

perl

In a HTML form, if we give names to input boxes with [], like this

<input name="foo[]" type="text" />
<input name="foo[]" type="text" />

In PHP, we can obtain values of these input boxes in an array, with $_POST['foo'].

How to do the similar in Perl? I use CGI.pm

like image 896
powerboy Avatar asked Aug 14 '10 23:08

powerboy


People also ask

How do I pass an array into a Perl script?

You can just pass the arguments, using system in the list form: system $^X, $program_name, @array; The list form bypasses the shell so it doesn't interpret metacharacters from your arguments (such as ; and & in the shell).

How do I assign an array to a variable in Perl?

Array variables are preceded by an "at" (@) sign. To refer to a single element of an array, you will use the dollar sign ($) with the variable name followed by the index of the element in square brackets. In Perl, List and Array terms are often used as if they're interchangeable.

What is dynamic array in Perl?

Perl arrays are dynamic in length, which means that elements can be added to and removed from the array as required. Perl provides four functions for this: shift, unshift, push and pop. shift removes and returns the first element from the array, reducing the array length by 1.

Is Perl used for CGI?

While CGI scripts can be written in many different programming languages, Perl is commonly used because of its power, its flexibility and the availability of preexisting scripts. sent to the server through CGI, the results may be sent to the client.


1 Answers

Just assign the result of param to an array.

my @values = param('foo[]');         # If you use the functional-style
my @values = $query->param('foo[]'); # If you use the OO-style of CGI.pm

There's no requirement that the name end with [].

like image 146
cjm Avatar answered Oct 25 '22 16:10

cjm