LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl/HTML Simple Practice (https://www.linuxquestions.org/questions/programming-9/perl-html-simple-practice-943267/)

ChozN 05-04-2012 08:48 AM

Perl/HTML Simple Practice
 
Hi, Im really new using perl. I just want to know how to make this possible

This is my code.

I want to click the button, when i click it, if i choose the process just use the command ($ps all), clean the window and show me all the process running in the moment, with a back to main window button. Then choose calendar (with the same, $cal) and just appear the calendar. I want to practice this method. Anything will be helpful. Thanks community.

Quote:

#!/usr/bin/perl

print <<ENDHTML;
<html>
<head>
<center><title>Practice</title></center>
<h1>Welcome to my site</h1>
</head>
<body>
<form action="">
<input type="radio" name="practice" value="process" /> View my process<br />
<input type="radio" name="practice" value="calendar" /> View the calendar<br />
<button type="button">Just Do It!</button>
</form>
</body>
</html>

ENDHTML
im always run the script, if works, just save it in html file like
./script > script.html, and open the file on browser

pan64 05-04-2012 10:03 AM

you will need a lot of practice.
In this example you generated a simple html page which can be viewed in a browser. If you want to change the content (that means it will respond to the clicks) you will need to install a web server and learn how to show a calendar and so on.

theNbomr 05-04-2012 11:50 AM

You need to study CGI. It is a method that allows a web server to launch a specified application that you write, which runs on the web server. In your case, the application would be specified by the 'action=""' expression in the HTML form. The (Perl) CGI would get the values of all of the HTML form elements, in order to know what it should do. It requires a CGI-capable web server in order to work. Apache is pretty much the standard, although I'm sure there are other, more light-weight servers as well.
If you are using Perl, you will also want to acquaint yourself with the CGI.pm module.
Please use [CODE][/CODE] tags when posting source code, to preserve formatting and prevent unwanted character translations.
--- rod.

ChozN 05-04-2012 03:16 PM

ok i already install apache2 web server on ubuntu (i put my index.html on www folder) right??! thanks anyways, also im not a web developer, this is the reason im really lost :'( any other suggestions will be helpful. Thanks pan64 and theNbomr.

theNbomr 05-04-2012 05:27 PM

You put all of your html files in the www directory, or whatever your web server has configured as its web root. There is usually a default index.html file that points you to help for the apache web server, or to help for the distro you are using.
Your Perl scripts (all CGIs) go in the cgi-bin directory. Typically, then, a URL that you can call directly, or might put in the 'action' property of an HTML form would look something like:
Code:

http://your.web.server/cgi-bin/yourPerlScript.pl
In the action property, you can simply identify the script as 'cgi-bin/yourPerlScript.pl', assuming you want it to use a script on the same saver. In real life, the URL may have an argument list that becomes part of the script's commandline arguments.

There is a plethora of online information that explains how web servers work ('HTTP protocol' is a good jumping-off point for research). One you have a basic grasp of that, then you can start exploring CGI methods. It isn't very complex; an afternoon of exploring and tinkering should get you most of the basics.
Some keywords and phrases that might lead you to useful search results:

"HTTP Get Method" "HTTP Post Method" "CGI" "HTTP protocol" "HTML" "HTTP Request" "CGI.pm"


It would be redundant to try to explain everything in this forum.

--- rod.

ChozN 05-04-2012 08:41 PM

you're great theNbomr! thanks a lot BUUT I'm doing something wrong. When I click Submit button, the myscript.pl never show...just an option to open or download the file myscript.pl loool ...well thanks anyways. +Rep 4 u!

theNbomr 05-05-2012 03:01 PM

It may be that your web server does not recognize Perl scripts as valid CGI scripts. You may be able to divine the correct settings by browsing the Apache config file(s). Is the script executable? Is it stored in the cgi-bin directory of your web server?
--- rod.


All times are GMT -5. The time now is 04:41 AM.