How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine

Reload this page Perl Programming

Here are my notes on programming in Perl (the Practical Extraction and Report Language) used on many websites. Let me know what you find helpful or missing.

Take the Brainbench certification test on Perl

 

Topics this page:

  • Versions
  • Installation
  • Debugging
  • Related:

  • Application Development
  • Web Projects
  • Web Development Tools
  • Javascript Coding
  • HTML Entity Codes
  •  

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page

    Search

    Set screen Summary

      Like Python, Perl is an interpretive language which is interpreted into machine code (compiled) by the computer while the program is running.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Releases and Versions

      Larry Wall began working on Perl while working for the U.S. National Security Agency (NSA) "Blacker" project. He released Perl as open source software to the comp.sources.misc newsgroup near the end of 1987. He released again in 1989 under the GNU public license.

      Download from ASPN.activestate the most prevalent distribution of Perl.

      There are distributions of Perl for many platforms: Windows, Linux, Solaris, etc.

      On Windows, choose an "ASC" or "MSI" (Windows System Installer).

      Sample code is available from companion websites to books on Perl:

      Strawberry Perl (W) by Adam Kennedy and others


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Installing Perl

      Install to C:\Perl.

      Invoke Perl by running a command window.

      1. Click on the Start menu.
      2. Click on Run.
      3. Type command at the Open prompt. If you are using Windows NT or 2000, you can also type cmd .
      4. Click OK for the black DOS command window.
      5. cd \Perl\eg for the samples folder.
      6. example.pl
        If you get a Notepad window, then you need to associate the file extension .pl to Perl.exe
      7. You can also

      8. perl -w example.pl

        You can also

      9. cd \yoursourcefolder
      10. perl -w aimslogs.pl to run your Perl program.
        If you get a Notepad window, then you need to associate the file extension .pl to Perl.exe


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Debugging Perl

      Part of the frustration with this language is its flexibility. As the Perl creed says: "There Is More Than One Way To Do It!"

      Here are my strategies for creating Perl programs quickly and reliably.

      1. Start with a plan - what actions will users perform?
      2. Start small - can the highest value feature be built first?
      3. Build code in segments
      4. Build in diagnostic routines right from the start.
      5. Use debug versions of code.



    Perl Tutorial from Leeds by Stephen Knilans. is my favorite - comprehensive, yet to-the-point, with exercises! It's part of the Perl Webring.

    Perl Tutorials, Manuals, References


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Tools

      Perl for Windows 32-bit systems is available as part of the MKS Toolkit.

      The use operator loads the ":standard" download cgi.pm library from Lincoln Stein, which contains a suite of methods that create forms and other HTML markup on-the-fly.

      The library also preserves the values entered in the form if the CGI script submits the form data back to itself.



    Perl Monks.org

    1PerlScripts.com.

    Quizes are part of Carleton Canada's Perl tutorials.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Ideas on Perl Programming

      Here's a sample program, with annotations.

      use CGI qw/:standard/;

      $foo = new CGI;

      $guest_record = $foo->param('guest_name')
      . ":" . $foo->param('email_address') ;

        retrieves data from the scalar string $foo.

        A dot is used to concatenate two strings.

      open STDERR, ">&STDOUT"
      open GUESTS, ">> guest.data"
      or die $foo->header,"Can't open guest database: $!\n";

        CGI borrows much of its syntax from UNIX.

      • STDIN and GUESTS are file handles.
      • STDIN -- the standard source of data input into a program -- is usually the console, what is typed on the keyboard.
      • The "less than sign" operator redirects file output "dir.txt" into the mail program.

          mail user5 < dir.txt

      • STDOUT -- the standard destination for output from the program -- is usually the console.
      • This command with the "less than sign" operator below redirects directory listing (ls) output to a file named "dir.txt".

          ls> dir.txt

      • If "dir.txt" does not exist, it will be created.
        If it already exists, it will be overwritten.
      • ">>" Double "greater than sign" appends (adds) output to the end of an existing file.
      • $! is a Perl built-in variable name for the error message created when an error occurs.

      open(RUN_PARMS, "| get_it");

        opens the RUN_PARMS file as input to a command named "get_it".

      open(FORMATTED_REPORT_FILE, "format_it |");

        opens the FORMATTED_REPORT_FILE to receive output to command named "format_it".

      while (<GUESTS>) {
      ($guest_name, $email_address, $phone_number, $browser) = split /:/;

        a loop to split the fields from a PUT statement the GUESTS file.

      print %ENV;

        prints the names and contents of all environment variables. %ENV is called a "hash", — an array which associates locations to values using strings instead of numbers.

      print "<A href=\"mailto:webmaster\@site.com\">Webmaster</A>. \n";

        Special character (such as @ and especially quote marks) must be escaped using the \ character within strings in Perl. Example:

      for ($count = 1; $count <= 10; $count += 1) { print("the counter is now $count\n"); }

      print GUESTS $guest_record, "\n";
      close GUESTS;

        "\n" is a line break.
        Semi-colons separate commands.

      In order to access an SQL database using Perl, there are two pieces required, they are

      • DBI module (the DataBase Interface) which enables a CGI program to access a database. DBD (DataBase Driver) module specific to a database, such as Oracle, Sybase, Informix, and Hughes Technologies' mSQL (MiniSQL). downloaded from http://www.Perl.com/CPAN/ (the Comprehensive Perl Archive Network). DBI and DBD can be found in category 7 of the archive called Database Interfaces.
      • The DBD:ODBC driver generically accesses ODBC, which in turn accesses the databases.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Portions ©Copyright 1996-2014 Wilson Mar. All rights reserved. | Privacy Policy |


    How I may help

    Send a message with your email client program


    Your rating of this page:
    Low High




    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 



      Top of Page Go to top of page

    Thank you!