Daniel
Daniel

Reputation: 289

html and perl, returning script text instead of running

I have been writing a html interface for displaying tables, pie charts, data etc.

The Perl script that generates the data and the tables can be called by a single command at the terminal and I want to have a button in the html that will call this. I don't really need any feedback from the Perl script once it's going, although if it could ping back a "everything went better than expected", that would be nice.

Currently however, every time I click the submit I get asked to open or save the Perl script and after a day of googling I cant fix it and would appreciate some advice.

I am new to html and js, but this is what I have so far:

<form action="scripts/do_processing.pl" method="get">
<table>
<td>Select input file: (must be fasta format)</td>
<td>
<input type="file" name="first_name" value="" maxlength="100" />
</td>
</tr>
<br>
<tr>
<tr><td>Binning:</td>
<td>
<input type="radio" name="bin_method" value="blastn" /> Blastn
<input type="radio" name="bin_method" value="blastx" /> Blastx
<input type="radio" name="bin_method" value="megan" /> Megan
</td>
</tr>
</table>
<br><br>
<input  TYPE=IMAGE 
        SRC="images/go_button-green.jpg" 
        HEIGHT=100 WIDTH=auto
        ALT="Go!" BORDER=0 
        NAME="go"
        >
</td>
</tr>
</form><br>

It is only to be ran locally, I have no intentions to have it accessible to the outside world and am therefore avoiding CGI and Apache-esque solutions which I think are unnecessary. Links are all good as it tries to open the file each time.

Note: The input is not relevant at the moment, as the perl script I'm currently trying to call is just a "Hello World!"

Upvotes: 0

Views: 455

Answers (3)

Eric Strom
Eric Strom

Reputation: 40142

As others have mentioned, you need some sort of server to act as glue between the browser and perl. A module I have written (Web::Gui) can act as that glue while writing all of the HTML and JavaScript for you:

use Web::Gui;

display(
    TABLE(
        TR(
            TD('Select input file: (must be fasta format)'),
            TD(INPUT type=>"file", id=>"first_name", maxlength=>100)
        ),
        TR(
            TD('Binning:'),
            TD(map BinMethod($_), qw(Blastn Blastx Megan)),
        ),
        TR(TD(colspan => 2,
            INPUT(type=>'button', value=>'Go', onclick=>sub {
                print "running app\n";
                print "file: ", ID(first_name)->value, $/;

                my $radios = gui('document')->getElementsByName('bin_method');
                my @values = map {$_->value} grep {$_->checked} @$radios;
                print "bin: @values\n";
            })
        ))
    )
);

sub BinMethod {
    INPUT(type=>"radio", name=>"bin_method", value=>lc $_[0]),
    SPAN($_[0])
}

Web::Gui isn't perfect (nor is it done) but it might be a good fit for your problem. A major update to XUL::Gui (of which Web::Gui is a part) is due soon. It will be enhancing Web::Gui with jQuery support, jQueryUI, and some improved syntax (eliminating the need for the SPAN tags in the above example among other things). I hope to have this update posted within the month (as soon as I can get my new asynchronous continuation-passing server rewrite to work without crashing :)

Upvotes: 1

Francisco Soto
Francisco Soto

Reputation: 10392

For what you are doing, you need to use a web server unfortunately.

In your case, when you open the HTML file locally, when you click on the form, your browser looks at the action and goes to that "address" based on where your web page is, since you are local, your webpage is a file:// url, so it basically goes to your perl file (which is what you want) except that the browser itself simply requests the file from your filesystem and does not know what to do with it, the filesystem DOES NOT run your perl script, it simply serves the file. So it's only posible response is to offer you to download it.

In the context of a web service, when you tell the server "go to this perl file" and assuming the web server is correctly configured, the web server notices that the .pl is a special file and it has to run it, so it does, and then grabs its output and sends it to your browser. Which is what you want to do.

Hope this helps.

Upvotes: 4

cdeszaq
cdeszaq

Reputation: 31280

In order to have something happen on the machine that hosts the HTML page, you need to have some sort of process that is looking for requests on port 80 to that machine. In all cases, this will be some sort of a "web server" simply because port 80 is the standard "web" port.

You could write your own simple server that listens for a request and runs the script, but I would suggest using an existing one that is light-weight and easy to set up.

Another option would be to do the same thing (have a listener) but at a different port.

Upvotes: 1

Related Questions