sending variablies from a dynamic table

C

cartercc

I have constructed a table using input from a database. It looks like
this:

<table>
<tr>
<td>Pat</td>
<td><input type="radio" name="sex1" value="M" /> Guy<br />
<td><input type="radio" name="sex1" value="F" /> Gal</td>
</tr><tr>
<td>Les</td>
<td><input type="radio" name="sex2" value="M" /> Guy<br />
<td><input type="radio" name="sex2" value="F" /> Gal</td>
</tr><tr>
<td>Sal</td>
<td><input type="radio" name="sex3" value="M" /> Guy<br />
<td><input type="radio" name="sex3" value="F" /> Gal</td>
</tr>
</table>

The table is generated from a database where there is no data in the
'gender' column. I cannot tell in advance how many rows will be
generated. I will pass the data to an update script that will write the
values to the 'gender' column. My script sends the appropriate string,
like 'page.cgi?user=me&role=manager&sex1=M&sex2=F&sex3=F'

I *could* use checkboxes and glob all the values together, like
'sex=v1M;v2F;v3F', read these into a variable, split the string, read
it into an array, and run a series of update queries (and will probably
wind up doing this for lack of something better), but I'd really like
to pass each value separately into its own variable, or better still,
to pass the whole thing as an arrayref to a series of hash refs, like
[{Pat=>'M'},{Les=>'F'},{Sal=>'F'}] ... but I don't know how to
dynamically allocate variables in a Perl script or perhaps use a client
side script to create and pass an array ref.

Ideas, anyone? I really, really would appreciate it.

CC
 
X

xhoster

I have constructed a table using input from a database. It looks like
this:

<table>
<tr>
<td>Pat</td>
<td><input type="radio" name="sex1" value="M" /> Guy<br />
<td><input type="radio" name="sex1" value="F" /> Gal</td>
</tr><tr>
<td>Les</td>
<td><input type="radio" name="sex2" value="M" /> Guy<br />
<td><input type="radio" name="sex2" value="F" /> Gal</td>
</tr><tr>
<td>Sal</td>
<td><input type="radio" name="sex3" value="M" /> Guy<br />
<td><input type="radio" name="sex3" value="F" /> Gal</td>
</tr>
</table>

The table is generated from a database where there is no data in the
'gender' column. I cannot tell in advance how many rows will be
generated. I will pass the data to an update script that will write the
values to the 'gender' column. My script sends the appropriate string,
like 'page.cgi?user=me&role=manager&sex1=M&sex2=F&sex3=F'

Do you really mean your script sends that strings? Or do you mean your
script writes an html form which, when interpreted, filled out, and
submitted, causes that string to be sent?
I *could* use checkboxes and glob all the values together, like
'sex=v1M;v2F;v3F', read these into a variable, split the string, read
it into an array, and run a series of update queries (and will probably
wind up doing this for lack of something better),

How are you going to get an html form to make something like that? Heavy
javascripting?
but I'd really like
to pass each value separately into its own variable, or better still,
to pass the whole thing as an arrayref to a series of hash refs, like
[{Pat=>'M'},{Les=>'F'},{Sal=>'F'}]

Why create a bunch of hashes which only have one key-value pair each? Why
not something more like {Pat=>'M',Les=>'F',Sal=>'F'}
And where did Pat, Les, and Sal come from? You submitted sex1, sex2, etc,
not actual names.

Something like:
my $ref= [ map {$_, $cgi->param($_)} grep /^sex\d+$/, $cgi->param() ];

should make something like:
{ sex1=>'M', sex2=>'F', sex3=>'F' }

(Assuming you are using CGI.pm to parse the forms and that the CGI object
is named $cgi)
... but I don't know how to
dynamically allocate variables in a Perl script

Do you mean that you know nothing about symbolic references, or that you
know nothing about any references?
or perhaps use a client
side script to create and pass an array ref.

Yeah, that's not going to happen. Look elsewhere.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top