Gossamer Forum
Home : General : Perl Programming :

A question of syntax ?

Quote Reply
A question of syntax ?
Hi folks,

I hope the Perl gods of the forum will smile on me and show me the error of my ways.

I have a shopping cart program that assigns field name on a per item basis (like $FORM{desc1}, $FORM{desc2}, etc)and I want to send the contents of the order form to an email address.

Now the email is working fine, however my problem is this : People may order more than one item, resulting in a form with many $FORM{descX}, where X is the number of items being orders. I don't want to hand code inputs to the email for $FORM{desc1-infinity} for obvious reasons(person may order one item), so what I have been attempting to do is this:

for ($i=1; $i<100; $i++){
while ('FORM{desc$i}'){
$body .= "Item :" . "('$FORM{desc$i}')\n";
}
}

This produces a server error "Invalid response". I have tried different combinations of quoting $i to try and get the value to read in to the FORM var (like desc3) to no avail.

Can anyone shed any light on the best way to accomplish my objective ?

Thanks much.

Quote Reply
Re: A question of syntax ? In reply to
Your while loop doesn't make sense there.

Code:
foreach my $key (sort keys %FORM) {
next unless ($key =~ /^desc(\d+)$/);
$body .= "Item: $FORM{$key}\n";
}
That will go through all the form input, and catch any key that starts with desc and a number and add it to the body.

Hope that helps,

Alex

--
Gossamer Threads Inc.