Tecnique and/or Modules for Perl and HTML

Discussion in 'Perl Misc' started by pgodfrin, Mar 1, 2008.

  1. pgodfrin

    pgodfrin Guest

    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
     
    pgodfrin, Mar 1, 2008
    #1
    1. Advertising

  2. pgodfrin

    Ron Bergin Guest

    On Mar 1, 7:42 am, pgodfrin <> wrote:
    > 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
     
    Ron Bergin, Mar 1, 2008
    #2
    1. Advertising

  3. pgodfrin

    Ron Bergin Guest

    On Mar 1, 7:42 am, pgodfrin <> wrote:
    > 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
     
    Ron Bergin, Mar 1, 2008
    #3
  4. pgodfrin

    pgodfrin Guest

    On Mar 1, 10:42 am, Ron Bergin <> wrote:
    > On Mar 1, 7:42 am, pgodfrin <> wrote:
    >
    >
    >
    > > 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


    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
     
    pgodfrin, Mar 1, 2008
    #4
  5. pgodfrin

    Ben Morrow Guest

    Quoth pgodfrin <>:
    > On Mar 1, 10:42 am, Ron Bergin <> wrote:
    > > On Mar 1, 7:42 am, pgodfrin <> wrote:
    > >
    > > > 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

    > >
    > > 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.


    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
     
    Ben Morrow, Mar 1, 2008
    #5
  6. pgodfrin

    pgodfrin Guest

    On Mar 1, 1:29 pm, Ben Morrow <> wrote:
    > Quoth pgodfrin <>:
    >
    >
    >
    > > On Mar 1, 10:42 am, Ron Bergin <> wrote:
    > > > On Mar 1, 7:42 am, pgodfrin <> wrote:

    >
    > > > > 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

    >
    > > > 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.

    >
    > 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
     
    pgodfrin, Mar 1, 2008
    #6
  7. pgodfrin

    pgodfrin Guest

    On Mar 1, 4:36 pm, pgodfrin <> wrote:
    > On Mar 1, 1:29 pm, Ben Morrow <> wrote:
    >
    >
    >
    > > Quoth pgodfrin <>:

    >
    > > > On Mar 1, 10:42 am, Ron Bergin <> wrote:
    > > > > On Mar 1, 7:42 am, pgodfrin <> wrote:

    >
    > > > > > 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

    >
    > > > > 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.

    >
    > > 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


    sim-sala-bim...

    I have seen the light...

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

    pg
     
    pgodfrin, Mar 2, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JohnPlayerSpecial

    Merge tecnique with XSL

    JohnPlayerSpecial, Apr 27, 2004, in forum: XML
    Replies:
    0
    Views:
    396
    JohnPlayerSpecial
    Apr 27, 2004
  2. gianguz
    Replies:
    10
    Views:
    731
    Swampmonster
    Dec 14, 2004
  3. ImpalerCore
    Replies:
    0
    Views:
    890
    ImpalerCore
    Mar 10, 2011
  4. Nate
    Replies:
    8
    Views:
    295
  5. garey
    Replies:
    3
    Views:
    178
    Joe Smith
    May 29, 2007
Loading...

Share This Page