Holy cats man,
I'm maintaining some pretty awful legacy code and there is a part for adding some values to the database from a HTML form created by a loop and increments the names of the variables it submits to 14, I'm changing the loop to the amount of rows it selects before creating the HTML.
But the issue is with how it inserts the HTML form back into the database.
Here's an ad-hoc version of the way it handles the database inserts
while (my $count <= 14) {
if ($count == 1) {
$name = $name1;
$email = $email1;
}
# ...
if ($count == 14) {
$name = $name14;
$email = $email14;
}
my $sth = $dbh->prepare("INSERT INTO table SET name = ? AND email = ?");
$sth->execute($name, $email);
$count++;
}
While I'm probably just going to rewrite this entire section, I'm curious if you could add something like;
elsif ($count > 14) {
# Say count is 15 and we want to assign
# $name to $name15 using a string and the $count variable here.
$name = "name".$count;
$email = "email".$count;
}
Is that technically feasible?