--- "Simon K. Chan" <[EMAIL PROTECTED]> wrote:
> Hi Everybody,
>
> I am trying to send an array as a hidden value in my script as follows:
>
> @array = (eggs, ham, bread, pop);
>
> foreach $food (@array){
> print "<INPUT TYPE=\"hidden\" NAME=\"food\" VALUE=\"$food\">";
> }
>
> My two questions are:
>
> 1. Is this the most efficient way of sending an array as a hidden value?
Hello Simon,
What do you mean by 'efficiency'? You could mean "most efficient" in terms of program
speed,
bandwidth, or ease of use. I am assuming that you mean ease of use. If so, I would
say "yes",
you have the most efficient method. However, it's not very robust. Consider the
following:
use strict;
my @array = ( 'Ovid', 'Fred Flintstone', 'Barney "the wimp" Rubble' );
foreach my $name ( @array ) {
print qq{<INPUT TYPE="hidden" NAME="name" VALUE="$name">\n};
}
In the above example, the HTML will be broken by the quotes marks embedded in Barney
Rubble's
name. To deal with that, use HTML::Entities. That will encode your data so it
doesn't mess up
your forms.
use strict;
use HTML::Entities;
my @array = ( 'Ovid', 'Fred Flintstone', 'Barney "the wimp" Rubble' );
foreach my $name ( @array ) {
$name = encode_entities( $name );
print qq{<INPUT TYPE="hidden" NAME="name" VALUE="$name">\n};
}
> 2. And if so, what is the corresponding $input{''} syntax?
use strict;
use CGI qw/:standard/;
my @food = param( 'food' );
Note that when using CGI.pm, the CGI::param function uses 'wantarray' to see if you're
expecting a
scalar or an array returned. If you were to do this:
my $food = param( 'food' );
CGI.pm would only give you the first food item. Using '@food' gives you all foods
listed.
Cheers,
Curtis Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]