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
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).
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.
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.
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.
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 []
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With