Gossamer Forum
Home : General : Perl Programming :

joining some form fields

Quote Reply
joining some form fields
i have the following code in a form:
Code:
print qq|<tr><td>Scores:</td>|;
my ($k) = 1;
while ( $k < 10 ) {
print qq|<td>&nbsp;<INPUT TYPE="TEXT" NAME="fs[$k]" SIZE="2" VALUE="$in{'fs[$k]'}" MAXLENGTH="2"></td>\n|; ++$k;
}
print qq|</tr>\n|;
after the form is submitted, i want to concatenate the nine scores fs[1] - fs[9] separated by a comma or a colon. i think the following code works:
Code:
$in{'Front9scores'} = $in{'fs[1]'} . ',' . $in{'fs[2]'} . ',' .$in{'fs[3]'} . ',' ......
but i would like something more elegant instead of typing each one. i tried this but it didn't work:
Code:
my ($test) = \@fs;

my ($k) = 1;
while ($k < 10 ) {
$in{'Front9scores'} .= $test[$k] . ':';
++$k
}
Quote Reply
Re: [delicia] joining some form fields In reply to
i got it working! i got rid of the [ ] in the form:
Code:
print qq|<td>&nbsp;<INPUT TYPE="TEXT" NAME="fs$k" SIZE="2" VALUE="$in{'fs$k'}" MAXLENGTH="2"></td>\n|; ++$k;

and then:
Code:
$in{'Front9scores'} .= $in{"fs$k"} . ':';

i guess the secret was double quotes instead of single quotes. does this look ok?
Quote Reply
Re: [delicia] joining some form fields In reply to
Yup, it would have been the single quotes

Basically:

Code:
$in{'fs[$k]'}

Would get saved literally as:

Code:
fs[$k]

(i.e $k is never evaluated)

Same as if you typed:

Code:
my $test = '$testing some strings';

the value of $test would actually still have $testing in it (and not its value) Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] joining some form fields In reply to
seems obvious now with your $test example. thanks!