Chuma:

As has been mentioned, it's not a big deal to have a local server running. As an example, you could use HTTP::Server::Simple::CGI or other server package to build a simple perl server that will serve up your web page and let you interact with it. As a trivial example, this is a simple program that will serve up a web page and accept data:

#!env perl { package PythonServer; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); use Data::Dump 'pp'; # URL paths to monitor my %dispatch = ( '/fetch' => \&fetch_page, '/save' => \&save_data, ); # Look up the path and execute the associated routine, or # give a typical 404 error sub handle_request { my ($self, $cgi) = @_; my $path = $cgi->path_info(); my $handler = $dispatch{$path}; if ("CODE" eq ref $handler) { print "HTTP/1.0 200 OK\r\n"; $handler->($cgi); return; } print "HTTP/1.0 404 Not found\r\n", $cgi->header, $cgi->start_html("Cheese Shoppe"), $cgi->h1("Sorry, We're fresh out of that one."), $cgi->end_html; } sub fetch_page { my $cgi = shift; return if !ref $cgi; print STDERR "Fetched page!\n"; open my $FH, '<', 'pm_1231092.html' or die "Can't open file: $ +!\n"; local $/; my $t = <$FH>; print $cgi->header; print $t; } sub save_data { my $cgi = shift; return if !ref $cgi; print STDERR "Got data: ", pp($cgi->{param}), "\n"; } } # Start up the server use strict; use warnings; my $pid = PythonServer->new(8088)->run; print "PID = $pid, press ^C to stop\n"; my $t = <>;

And here's the web page that it will serve up:

<html> <head> <title>A whimsical form</title> </head> <body> <h2>What is the airspeed of a laden swallow?</h2> <form action="/save"> <table class="things"> <tr><th>Number of Cocoanuts:</th> <td><input type="text" name="NumCocoanuts"/></td></tr> <tr><th>Swallow Type:</th> <td><select name="SwallowType"> <option>African</option> <option>European</option> </select> </td> </tr> </table> <input type="submit" value='Calculate Airspeed'/> </form> </body> </html>

This is an admittedly crude example, but it works. All you need to do is add subroutines to the %dispatch table to let the server handle other actions, create the appropriate web pages, and write the JavaScript you want to use to handle the user interactions.

The console output of a sample run gave me:

$ perl pm_1231092.pl PythonServer: You can connect to your server at http://localhost:8088/ Fetched page! Got data: { NumCocoanuts => [1], SwallowType => ["European"] }

I hope this gives you a starting point to play with.

Note: Internet Explorer for the win! That's a phrase I never thought I'd utter. Frikkin' Chrome kept blocking my attempt at putting in the html page of the example in there.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Running local Perl from HTML by roboticus
in thread Running local Perl from HTML by Chuma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.