| Casual Articles |
Hubs | Hubbers | Topics | Request |
| #1 in Business | Subscribe Email Print |
|
You are here: Home > Internet and Businesses Online > Web Development > Running a CGI Script on a Web Server |
|
Casual Articles - Running a CGI Script on a Web Server
Power Transformer Basics >
rename "before.htm.bak", "before.htm";Transformer is an electrical machine so as to transfer power commencing one circuit to a different by transformer attractive combination through no affecting parts. Transformer comprise of two or supplementary attached windings otherwise a single tap windy and, in most cases, Transformer a magnet, the category of the magnet cover all method of strategy intended to create, conduct, straight, exchange otherwise defend the abuser from electrical liberation.Most important produce families contained by electrical and electronic mechanism consist of batteries, connectors, inactive electronic mechanism, electrical allocation and defense gear fuse, supremacy supplie This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. V To run a Perl script that is installed on your computer, which needs to process one or more files on your computer, and where the Perl interpreter is also installed on your computer, is very simple - you just need to double-click the perl script and it does the business - assuming that everything is set up correctly of course, for example, the location of the perl.exe program is defined in your path. You can also open a DOS window and type perl perlfile.pl to run a script (where perlfile.pl is the name of the Perl script you want to run). However, when it comes to running a Perl script, or CGI script, on a web server, things can be a bit trickier - not too tricky, but a bit trickier. In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server. The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name. Version 1 - the local version Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article. localScript.pl $name = "before.htm" or die "cannot assign to variable: $!"; This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. V However, when it comes to running a Perl script, or CGI script, on a web server, things can be a bit trickier - not too tricky, but a bit trickier. In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server. The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name. Version 1 - the local version Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article. localScript.pl $name = "before.htm" or die "cannot assign to variable: $!"; This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. V The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name. Version 1 - the local version Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article. localScript.pl $name = "before.htm" or die "cannot assign to variable: $!"; This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. V localScript.pl $name = "before.htm" or die "cannot assign to variable: $!"; This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. V This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created. The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed. Version 2 - the web server version Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser. webScript.cgi #!/usr/bin/perl -w A couple of initial points to note: 1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server. 2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally. Ok, lets go through the script line by line to see what's going on. Running the script To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably b
HTTP = HTML link (for blogs, profiles,phorums):
Related Articles:Chartering a Private Jet Makes Good Business Sense How to Create a Compelling Profile on My Speed Business Network Pay Per Click Advertising For Home Business Owners
|