C
cartercc
Can I assign a function to a scalar as a ref in a module file and call
the function by using the scalar in a heredoc?This is for a web app. I
have three components, a module, a CGI script, and a database. This is
a front end to a database which runs select, update, insert, and
delete queries and displays the results.
I have a bunch of standard functions in the module, such as
print_header(), print_footer(), print_link(), connect_to_database(),
etc., along with some global variables.
I have a CGI script that starts off like this:
use CGI;
use DBI;
use WebModule;
And mostly consists of a heredocs that output pure html.
And I have a database (Postgres).
The CGI script contains mostly forms for passing data to the
database. I'm using heredocs to spit out the html. I'm finding that I
am repeating a bunch of code, six times now, which looks like this:
<td><select name="postype">
<option>Classified</option>
<option>Faculty</option>
<option>Lecturer</option>
<option>PartTime</option>
<option>Professional</option>
<option>RFP</option>
<option>Vacant</option>
</select>
</td>
I can create a function that prints this to the html document, but
that involves ending the heredoc, calling the function, and then
starting the heredoc, like this:
print <<form;
<!-- pure html -->
form
print_select_element_in_form();
print <<form;
<!-- more pure html -->
form
Here is the question: Can I assign this function to a scalar ref in my
module file and call the function by using the scalar in the heredoc?
I'm slightly frustrated as I have spent most of the morning in a
futile attempt to do this (and I'm sure that I'm making some stupid
mistake, or maybe it can't be done.)
TIA, CC.
the function by using the scalar in a heredoc?This is for a web app. I
have three components, a module, a CGI script, and a database. This is
a front end to a database which runs select, update, insert, and
delete queries and displays the results.
I have a bunch of standard functions in the module, such as
print_header(), print_footer(), print_link(), connect_to_database(),
etc., along with some global variables.
I have a CGI script that starts off like this:
use CGI;
use DBI;
use WebModule;
And mostly consists of a heredocs that output pure html.
And I have a database (Postgres).
The CGI script contains mostly forms for passing data to the
database. I'm using heredocs to spit out the html. I'm finding that I
am repeating a bunch of code, six times now, which looks like this:
<td><select name="postype">
<option>Classified</option>
<option>Faculty</option>
<option>Lecturer</option>
<option>PartTime</option>
<option>Professional</option>
<option>RFP</option>
<option>Vacant</option>
</select>
</td>
I can create a function that prints this to the html document, but
that involves ending the heredoc, calling the function, and then
starting the heredoc, like this:
print <<form;
<!-- pure html -->
form
print_select_element_in_form();
print <<form;
<!-- more pure html -->
form
Here is the question: Can I assign this function to a scalar ref in my
module file and call the function by using the scalar in the heredoc?
I'm slightly frustrated as I have spent most of the morning in a
futile attempt to do this (and I'm sure that I'm making some stupid
mistake, or maybe it can't be done.)
TIA, CC.