Tecnique and/or Modules for Perl and HTML

P

pgodfrin

Greetings,

Could someone point me in the right direction? I'm not a web developer
- just a budding perl dude (who's really a database guy).

I'd like to (at first) read from database (using DBI) and display the
contents on a web page. The trick is I want to do it on the same page
that the action button resides and pop the output of the perl program
into a scrollable box. Nothing fancy - just output some data from a
database call. Eventually I'd like to be able to pass variables from a
form to the waiting perl program

There is a bunch of confusing stuff out there everything from
javascript to embperl and then Mason. And the unspeakable PHP of
course...

Can anyone offer some advice where I should go? (ok - no wisecracks...
<grin>)

thanks,
pg
 
R

Ron Bergin

Greetings,

Could someone point me in the right direction? I'm not a web developer
- just a budding perl dude (who's really a database guy).

I'd like to (at first) read from database (using DBI) and display the
contents on a web page. The trick is I want to do it on the same page
that the action button resides and pop the output of the perl program
into a scrollable box. Nothing fancy - just output some data from a
database call. Eventually I'd like to be able to pass variables from a
form to the waiting perl program

There is a bunch of confusing stuff out there everything from
javascript to embperl and then Mason. And the unspeakable PHP of
course...

Can anyone offer some advice where I should go? (ok - no wisecracks...
<grin>)

thanks,
pg

Have you looked at the CGI module? The synopsis section will give you
a hint on part of what you need. By the time you finish reading the
doc, you should have a pretty good idea where to start. After you've
made an attempt, post back with specific questions and example code
that demonstrates the problem that you're having.
http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm
 
R

Ron Bergin

Greetings,

Could someone point me in the right direction? I'm not a web developer
- just a budding perl dude (who's really a database guy).

I'd like to (at first) read from database (using DBI) and display the
contents on a web page. The trick is I want to do it on the same page
that the action button resides and pop the output of the perl program
into a scrollable box. Nothing fancy - just output some data from a
database call. Eventually I'd like to be able to pass variables from a
form to the waiting perl program

There is a bunch of confusing stuff out there everything from
javascript to embperl and then Mason. And the unspeakable PHP of
course...

Can anyone offer some advice where I should go? (ok - no wisecracks...
<grin>)

thanks,
pg

Have you looked at the CGI module? The synopsis section will give you
a hint on part of what you need. By the time you finish reading the
doc, you should have a pretty good idea where to start. After you've
made an attempt, post back with specific questions and example code
that demonstrates the problem that you're having.
http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm
 
P

pgodfrin

Have you looked at the CGI module? The synopsis section will give you
a hint on part of what you need. By the time you finish reading the
doc, you should have a pretty good idea where to start. After you've
made an attempt, post back with specific questions and example code
that demonstrates the problem that you're having.http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm

Yep - I've even run the samples. Perhaps it's a conceptual thing, but
it seems to me that the CGI module is all encompassing. When it's run
- it must produce the entire web page. Which is not what I think I
want.

I'm not having a problem per se, but a conceptual quagmire - I have a
web page, I just want to slap a table or text box in the middle of it
with data from a perl DBI query. Maybe that's not how you do it...
pg
 
B

Ben Morrow

Quoth pgodfrin said:
having.http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm

Yep - I've even run the samples. Perhaps it's a conceptual thing, but
it seems to me that the CGI module is all encompassing. When it's run
- it must produce the entire web page. Which is not what I think I
want.

It is, though :). Except for modern JS-based techniques like Ajax, which
I would suggest you avoid for now, the way the web works is whole pages
at a time. If you re-read the docs for CGI.pm, you will find it has lots
of methods for re-requesting the current page with something slightly
different, and for preserving your program's state across several
invocations of the 'same' page.

Try this. It's not necessarily a good example of how to use CGI, the
HTML-generation is very simple-minded, and of course passing anything
to 'eval' is just downright stupid; but it should give you an idea of
how such programs work.


#!/usr/bin/perl -T

use strict;
use warnings;
use CGI;

my $Q = CGI->new;
my $url = $Q->url;

print $Q->header;

print <<HTML;
<html>
<head><title>Calculator</title></head>
<body>
<h2>Enter an arithmetic expression:</h2>
<form action="$url" method="POST">
<input name="eval"> <input type="submit" value="Eval">
</form>
HTML

if (my $expr = $Q->param('eval')) {

print <<HTML;
<!-- $expr -->
HTML

if (my ($safe) = $expr =~ m{^([-+/*()\d. ]+)$}) {
my $val = eval $safe;
if (defined $val) {
print <<HTML;
<p>Result: $val.</p>
HTML
}
else {
print <<HTML;
<p style="color: red;">Syntax error: $@</p>
HTML
}
}
else {
print <<HTML;
<p style="color: red;">Bad input.</p>
HTML
}
}

print <<HTML;
</body>
</html>
HTML

__END__

Ben
 
P

pgodfrin

Quoth pgodfrin <[email protected]>:


Yep - I've even run the samples. Perhaps it's a conceptual thing, but
it seems to me that the CGI module is all encompassing. When it's run
- it must produce the entire web page. Which is not what I think I
want.

It is, though :). Except for modern JS-based techniques like Ajax, which
I would suggest you avoid for now, the way the web works is whole pages
at a time. If you re-read the docs for CGI.pm, you will find it has lots
of methods for re-requesting the current page with something slightly
different, and for preserving your program's state across several
invocations of the 'same' page.

Try this. It's not necessarily a good example of how to use CGI, the
HTML-generation is very simple-minded, and of course passing anything
to 'eval' is just downright stupid; but it should give you an idea of
how such programs work.

#!/usr/bin/perl -T

use strict;
use warnings;
use CGI;

my $Q = CGI->new;
my $url = $Q->url;

print $Q->header;

print <<HTML;
<html>
<head><title>Calculator</title></head>
<body>
<h2>Enter an arithmetic expression:</h2>
<form action="$url" method="POST">
<input name="eval"> <input type="submit" value="Eval">
</form>
HTML

if (my $expr = $Q->param('eval')) {

print <<HTML;
<!-- $expr -->
HTML

if (my ($safe) = $expr =~ m{^([-+/*()\d. ]+)$}) {
my $val = eval $safe;
if (defined $val) {
print <<HTML;
<p>Result: $val.</p>
HTML
}
else {
print <<HTML;
<p style="color: red;">Syntax error: $@</p>
HTML
}
}
else {
print <<HTML;
<p style="color: red;">Bad input.</p>
HTML
}

}

print <<HTML;
</body>
</html>
HTML

__END__

Ben

Hi Ben,
Always good to hear from you. I feel like - forgive the expression -
you're my fairy godmother... <grin>

I will read the docs a little closer - I must have been looking for a
silver bullet and peeked at the doc in a somewhat lazy manner.

thanks, as always,
pg
 
P

pgodfrin

It is, though :). Except for modern JS-based techniques like Ajax, which
I would suggest you avoid for now, the way the web works is whole pages
at a time. If you re-read the docs for CGI.pm, you will find it has lots
of methods for re-requesting the current page with something slightly
different, and for preserving your program's state across several
invocations of the 'same' page.
Try this. It's not necessarily a good example of how to use CGI, the
HTML-generation is very simple-minded, and of course passing anything
to 'eval' is just downright stupid; but it should give you an idea of
how such programs work.
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;
my $Q = CGI->new;
my $url = $Q->url;
print $Q->header;
print <<HTML;
<html>
<head><title>Calculator</title></head>
<body>
<h2>Enter an arithmetic expression:</h2>
<form action="$url" method="POST">
<input name="eval"> <input type="submit" value="Eval">
</form>
HTML
if (my $expr = $Q->param('eval')) {
print <<HTML;
<!-- $expr -->
HTML
if (my ($safe) = $expr =~ m{^([-+/*()\d. ]+)$}) {
my $val = eval $safe;
if (defined $val) {
print <<HTML;
<p>Result: $val.</p>
HTML
}
else {
print <<HTML;
<p style="color: red;">Syntax error: $@</p>
HTML
}
}
else {
print <<HTML;
<p style="color: red;">Bad input.</p>
HTML
}

print <<HTML;
</body>
</html>
HTML

Ben

Hi Ben,
Always good to hear from you. I feel like - forgive the expression -
you're my fairy godmother... <grin>

I will read the docs a little closer - I must have been looking for a
silver bullet and peeked at the doc in a somewhat lazy manner.

thanks, as always,
pg

sim-sala-bim...

I have seen the light...

I think I'm gonna start calling you Yoda...

pg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top