Re: posting an array
- From: Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- Date: Sat, 23 Jul 2005 21:50:53 +0200
Mark D Smith wrote:
i am posting a hidden values called accounts which is a number of usernames pushed to an array.
print "<input type=hidden name=accounts value=\"@accounts\">";
the page that receives the data should be able to unpack the array but i am having problems
&ReadParse();
foreach $line(@in) { print "$line <br>\n"; }
shows accounts=username+username_001+username_002+username_003 as expected
but
$cnt=0; @accounts = $in{'accounts'}; foreach $line(@accounts) { print "$line<br>\n"; $cnt++; } print $cnt;
username username_001 username_002 username_003 1
all on 1 line, not 1 line for each value in the array.
what have i missed
You seem to have missed a few things. First, what you post via a form control is a string, not a list.
An array, such as
my @accounts = qw/name1 name2 name3/;
returns a string with the elements separated with spaces and concatenated, if you surround it with double quotes.
If the usernames don't contain space characters, you can try
@accounts = split ' ', $in{'accounts'};Another thing is that your Perl coding style seems to be outdated. Please make it a habit to my() declare the variables and enable strictures and warnings. Also, it may be a good idea to start using the standard module CGI.pm instead of cgi-lib.pl (or whatever code you are referring to with "&ReadParse();").
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl .
- Follow-Ups:
- Re: posting an array
- From: Mark D Smith
- Re: posting an array
- References:
- posting an array
- From: Mark D Smith
- posting an array
- Prev by Date: Re: posting an array
- Next by Date: Re: copy contructor
- Previous by thread: Re: posting an array
- Next by thread: Re: posting an array
- Index(es):
Relevant Pages
|