Casual Articles
#1 in Business Subscribe Email Print

You are here: Home > Internet and Businesses Online > Web Development > Running a CGI Script on a Web Server

Tags

  • magnet
  • itself
  • appropriate
  • called afterhtm
  • appropriate places

  • Links

  • Lease Medical Equipment for Optimal Financial Results
  • Grant Funding for Small Businesses
  • Put In The Work And You Will Reap The Rewards
  • Casual Articles - Running a CGI Script on a Web Server

    Power Transformer Basics
    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
    > rename "before.htm.bak", "before.htm";

    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

    Entrepreneur to Employer
    You make the decision to go into business and for some time work from home or in leased premises and your business starts to grow.Like all businesses you experience growing pains. Cash Flow is sometimes tight, customers come in ebbs and flows but you continue to make progress.You win a few major contracts and at the back of your mind you realise you need to make some important decisions for the future.Your hours at work have been steadily increasing and the reason you went into business, lifestyle, more time with the children, sport, or whatever your passion is, these important parts of your life have been dropping off lately and you find yours
    For many years I have been writing Perl scripts to process ASCII files of one sort or another on my computer. I typically do this when I need to reformat or tidy up a series of HTML pages, for example.

    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: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    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

    How to Put Video on your Website: Video File Types
    There are three basic video file types on the internet. Mpeg, AVI and Quicktime. I believe the Quicktime file type is the most popular since a lot of huge entertainment and news sites use it exclusively on their web pages.AVI is the oldest of the three main file types. It is a windows oriented video format but it's not the most popular because of the sound and video compatibility and synchronizing problems. Because the Quicktime format can be used on either a windows or a macintosh computer, the AVI video file type loses it's popularity every day.The mpeg format is a popular video file type that uses it's high output quality to increase it's popularit
    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: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    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

    Network Marketing - Understanding Your Target Market
    Network Marketing is no different to any other business. In order to succeed it is essential to understand your target market.Promoting your opportunity to the wrong audience will drain your cashflow and eventually force you out of business. But it is amazing how many network marketers are unaware of this basic marketing principle.So many upline leaders teach the "shot gun" approach of making your list, getting information to them and seeing who sticks. This is one of the reasons we have a 95% failure rate in this industry.The bottom line is that any network marketer really needs to learn the basics of target marketing in order to succeed in th
    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: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    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

    5 Things You Need to Do Every Day to Explode Your Traffic
    If you do these 5 simple things every day, you will grow your traffic exponentially. Warning! These tasks are very tedious. So tedious in fact that 99.9% of all businesses fail on the Internet because they do not follow these 5 simple undertakings every single day.Task 1: Submit 2 articles a day to over 200 article directoriesThis might sound like a daunting task, but, the more articles you write and submit, the more chances people are going to get to know you.When you write an article, make sure it has something to do with your business, make sure it makes you look like an authority on your subject, and make sure you c
    've done this wherever necessary in this article.

    localScript.pl

    $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    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

    Customer Service - A Lost Art?
    Is customer service a lost art? Before you answer that question, take a moment and think about the last few times you have gone shopping or out to dinner. Okay, now that you have really thought about it, is your answer any different?Why is it that when we actually DO receive excellent customer service that it makes such an impression on us that we usually choose to go back? Why - because the occurrences are so few and far between!!!As a home business owner, it is imperative to my business that customer service is ALWAYS a top priority. Remember the saying: “If you don’t take care of your customer, somebody else will”. I’m sure you have read or heard i
    > rename "before.htm.bak", "before.htm";

    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
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    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):
    <a href="http://www.casualarticles.com/article/86350/casualarticles-Running-a-CGI-Script-on-a-Web-Server.html">Running a CGI Script on a Web Server</a>

    BB link (for phorums):
    [url=http://www.casualarticles.com/article/86350/casualarticles-Running-a-CGI-Script-on-a-Web-Server.html]Running a CGI Script on a Web Server[/url]

    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

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com