Re: posting an array



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
.



Relevant Pages

  • Re: Optimization help - reading out of /proc on Solaris
    ... string slicing and unpacking. ... we have a symbol mapping to an unpack format string segment ... #repeat the above with a new array instead of FIELDS and a new method name ... # # Print process table information for only pid 1001 ...
    (comp.lang.ruby)
  • Re: Reading compressed file and its conversion to numbers.
    ... that it all has to be put in a string -- so you should join the array ... So when you pass in an array reference to unpack(), ...
    (comp.lang.perl.misc)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)