Tutorials

My First Perl Program

Program that prints out Hello, World! (let's call our file hello.pl):
  #!/usr/bin/perl
  print "Hello, World!\n";
  • The first line signifies where the perl interpreter resides on the host system. This is usually /usr/bin/perl on Linux systems and /bin/perl under *NIX systems.
  • The next statment is a simple print statement. That's it.

    Switches
    The perl interpreter has useful switches.
  • The -c switch lets perl check for syntax only, without running the actual program.
  • The -w turns on all useful warnings. You should ALWAYS develop your programs under -w.

    So how would you actually run this program? You could run it as:
    $perl -w hello.pl
    or we could make the perl file executable, by using the chmod command:
    $chmod 700 hello.pl
    $./hello.pl

    How do I issue the -w flag? Simple, put it in the perl line at line
    #!/usr/bin/perl -w.

    A comment in Perl begins with #.
  • Perl
    My First Perl Program
    Perl Scalars
    Perl Lists
    Perl Operators
    Perl Arrays
    Perl Hashes
    Perl If..elsif..else
    @ARGV and %ENV
    Perl Loop statements
    Perl Subroutines
    Perl References
    Perl Regular Expressions
    Perl File Operations
    Perl Objects, Classes
    Perl DBI (Databases)
    Perl Signals
    Perl command line..
    Perl Special Variables
    Perl Reference
    Perl SOAP
    Perl Threads