C
ccc31807
I've been asked to maintain a web application/site which runs on
Linux, Postgres, Apache, and Perl.
The script contains these lines which query a database:
my $page = param('page');
my $person = param('person');
my $doc_ref = get_doc_ref($page);
my $per_ref = get_per_ref($person);
When I print the values, this is what I get:
print $doc_ref->[0] returns
<body>
<h1>Hello, #a_name#</h1>
<p>You have won #a_prize#.</p>
</body>
print $per_ref->{a_name) returns 'John Smith'
print $per_ref->{a_prize} returns 'dinner at Outback Steakhouse'
The next line assigns the $doc_ref to a scalar:
my $doc = $doc_ref->[0];
My question relates to the IN BETWEEN code here, which I'll come back
to.
After the IN BETWEEN code executes, we have this:
print $doc;
This results in the the following:
<body>
<h1>Hello, John Smith</h1>
<p>You have won dinner at Outback Steakhouse.</p>
</body>
Here is the IN BETWEEN code:
$doc =~ s/#a_name#/$per_ref->{a_name}/g;
$doc =~ s/#a_prize#/$per_ref->{a_prize}/g;
.... and so on for a large number of variables. There are many pages,
and some of the pages contain thousands of different values.
I have tried several different ways to fold the $per_ref data into the
$doc without the IN BETWEEN code, all without success. My question is
whether this is even possible? Do I have to accept the IN BETWEEN
substitutions, or can I directly update one scalar variable ($doc)
with a number of other scalars?
The good news is that the old code works perfectly. The bad news is
that I'm staring at a lot of mindless coding. If I could change the
database and have everything automatically update, I'd be very happy.
Thanks, CC.
Linux, Postgres, Apache, and Perl.
The script contains these lines which query a database:
my $page = param('page');
my $person = param('person');
my $doc_ref = get_doc_ref($page);
my $per_ref = get_per_ref($person);
When I print the values, this is what I get:
print $doc_ref->[0] returns
<body>
<h1>Hello, #a_name#</h1>
<p>You have won #a_prize#.</p>
</body>
print $per_ref->{a_name) returns 'John Smith'
print $per_ref->{a_prize} returns 'dinner at Outback Steakhouse'
The next line assigns the $doc_ref to a scalar:
my $doc = $doc_ref->[0];
My question relates to the IN BETWEEN code here, which I'll come back
to.
After the IN BETWEEN code executes, we have this:
print $doc;
This results in the the following:
<body>
<h1>Hello, John Smith</h1>
<p>You have won dinner at Outback Steakhouse.</p>
</body>
Here is the IN BETWEEN code:
$doc =~ s/#a_name#/$per_ref->{a_name}/g;
$doc =~ s/#a_prize#/$per_ref->{a_prize}/g;
.... and so on for a large number of variables. There are many pages,
and some of the pages contain thousands of different values.
I have tried several different ways to fold the $per_ref data into the
$doc without the IN BETWEEN code, all without success. My question is
whether this is even possible? Do I have to accept the IN BETWEEN
substitutions, or can I directly update one scalar variable ($doc)
with a number of other scalars?
The good news is that the old code works perfectly. The bad news is
that I'm staring at a lot of mindless coding. If I could change the
database and have everything automatically update, I'd be very happy.
Thanks, CC.