How could I make it so that the value of a scalar is used in a hash? Here is my code:
The scalar ($content)is a $query->param(), and the hash is a list of possible values of the scalar and the text file it has to open in the case of each value. When I run the script, it either gives me a syntax error or an error that says the file doesn't exist, which it does. Any ideas?
Code:
my %contentfiles = [ login => $ENV{DOCUMENT_ROOT}."/templates/content/logincontent.txt",
passfnd => $ENV{DOCUMENT_ROOT}."/templates/content/passfndcontent.txt",
signup => $ENV{DOCUMENT_ROOT}."/templates/content/signupcontent.txt",
services => $ENV{DOCUMENT_ROOT}."/templates/content/servicescontent.txt",
compare => $ENV{DOCUMENT_ROOT}."/templates/content/comparecontent.txt",
capabilities => $ENV{DOCUMENT_ROOT}."/templates/content/capabilitiescontent.txt",
violation => $ENV{DOCUMENT_ROOT}."/templates/content/violationscontent.txt",
billing => $ENV{DOCUMENT_ROOT}."/templates/content/billingcontent.txt",
other => $ENV{DOCUMENT_ROOT}."/templates/content/othercontactscontent.txt",
about => $ENV{DOCUMENT_ROOT}."/templates/content/aboutcontent.txt",
history => $ENV{DOCUMENT_ROOT}."/templates/content/historycontent.txt" ];
my $template_file = $ENV{DOCUMENT_ROOT}."/templates/main.tmpl";
my $tmpl = new HTML::Template( filename => $template_file );
my $dropdown = $ENV{DOCUMENT_ROOT}."/templates/content/dropmenu.txt";
my $contentfile = read_file($contentfiles{$content});#The offending line
my $dropmenu = read_file($dropdown);
The scalar ($content)is a $query->param(), and the hash is a list of possible values of the scalar and the text file it has to open in the case of each value. When I run the script, it either gives me a syntax error or an error that says the file doesn't exist, which it does. Any ideas?