Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
Perl-CGI Example-01
  • Sh3llc0d3
    Posts: 1,910
    Well I got the examples idea from chronic and thought i'd add some variety into the perl section. CGI is server side scripting, you can create CGI scripts in several languages, python being another example but perl being the focus of this example.

    #!C:/Perl64/bin/Perl.exe -w
    # CGI Example1
    use CGI;

    print \"Content-Type: text/html\n\n\";

    print <<\"EOF\";
    <HTML>
    <HEAD>
    <TITLE>Hello, world!</TITLE>
    </HEAD>

    <BODY>
    <h1>Hello, world!</h1>
    <hr>
    <p>This is a crappy example for you guys :P</p>
    <hr>
    </BODY>
    </HTML>
    EOF


    As you can see, this script looks pretty much in the broad aspect like a normal perl script. Notice the "use CGI;". CGI can be scripted a few ways, another being to 'print' every single line of HTML or like this example script a block of HTML code and then print it. This is the easiest :P

    For Perl-CGI what do you need to know? HTML, and to a degree a fair amount of perl. You can create a simple HTML page, however for complex pages which involve forms, variable handling, POST/GET you'll need to know perl if you want it all integrated into one script. You could use a seperate script however that'd be pretty much pointless.

    If you want to try this example out, fiddle about with it and have a go. Make sure you change "#!C:/Perl64/bin/Perl.exe" to where ever your perl is, usually in *nix "/usr/bin/perl" or "C:/Perl/bin/Perl.exe" for windows x86/32bit
  • Xin
    Posts: 3,251
    Nice tutorial, keep them coming this is interesting.
    Xin
  • Sh3llc0d3
    Posts: 1,910
    said:


    Nice tutorial, keep them coming this is interesting.



    Thanks Xin, will add more complex ones soon. Not feeling so well today so will probably be later or tomorrow.
  • Bursihido
    Posts: 406
    Thanks nice Tutorial bro : )
  • Sh3llc0d3
    Posts: 1,910
    said:


    Thanks nice Tutorial bro : )



    Thanks Bursihido, not much of a tutorial but it's a very simple example of how good perl-cgi can be used. I'll do another one on using html forms (GET method) with cgi.