Hi all:
I have a perl CGI script that has checkboxes for 4 different elements. Call the elements 1 2 3 4.
Depending on the selections made an email attachment is included.
Example, check 1 & 3 and the email will have the attachments corresponding to 1 & 3
So with 4 elements there are a possible 16 non-repeatable combinations - NOT permutations.
There are 2**4 possibilities, including NULL.
Since there are 4 elements = 16 possible combinations, I just hard coded the 16 possibilities thinking I will find a solution later.
Later has come. I need to add a 5th element meaning there are now 32 possible non-repeating combinations. 2**5 = 32
And if I have to add a 6th element, which is a very real possibility, there would be 64 possible combinations.
Example of what I am doing now. And my question is, how can I do it better?
I have a perl CGI script that has checkboxes for 4 different elements. Call the elements 1 2 3 4.
Depending on the selections made an email attachment is included.
Example, check 1 & 3 and the email will have the attachments corresponding to 1 & 3
So with 4 elements there are a possible 16 non-repeatable combinations - NOT permutations.
Code:
1, 2, 3, 4, 1&2, 1&3, 1&4, 2&3, 2&4, 1&2&3, 1&2&4, 2&3&4, etc...
There are 2**4 possibilities, including NULL.
Since there are 4 elements = 16 possible combinations, I just hard coded the 16 possibilities thinking I will find a solution later.
Later has come. I need to add a 5th element meaning there are now 32 possible non-repeating combinations. 2**5 = 32
And if I have to add a 6th element, which is a very real possibility, there would be 64 possible combinations.
Example of what I am doing now. And my question is, how can I do it better?
Code:
sub mailit134 {
my $path_to_1 = "/var/[URL unfurl="true"]www/html/1.html";[/URL]
my $1filename = "1_instructions.html";
my $path_to_3 = "/var/[URL unfurl="true"]www/html/3_instructions.html";[/URL]
my $3filename = "3_instructions.html";
my $path_to_4 = "/var/[URL unfurl="true"]www/html/4_instructions.html";[/URL]
my $4filename = "4_instructions.html";
my $msg = MIME::Lite->new(
Subject => "Support",
From => "Support",
To => $cust,
Type => 'text/html',
Encoding => '7bit',
Data => $comments);
$msg->attach(
Type => 'text/html',
Path => $path_to_1,
Filename => $1filename,
Disposition => "attachment");
$msg->attach(
Type => 'text/html',
Path => $path_to_3,
Filename => $3filename,
Disposition => "attachment");
$msg->attach(
Type => 'text/html',
Path => $path_to_4,
Filename => $4filename,
Disposition => "attachment");
$msg->send();
&logit;
}