Perl

From Deep Thought

Jump to: navigation, search

Cyber Sprocket is well versed in multiple programming languages, including Perl. Perl was prolific in the 90's when web-based CGI programming was getting underway.

If you have a Perl based project, we can help. Just ask to speak to one of our Perl experts.

Contents

About Perl

Perl is a programming language originally developed for text manipulation on Unix systems. Perl is used for a variety of tasks on multiple operating systems, although the presence is most prolific on Unix or Linux systems. You can find Perl being used for web development, system administration, network programming, GUI development, and more.

Perl Command Line Switches

The Perl command line can be accessed from any SSH or telnet session on your Linux/Unix servers. Available commands for perl:

Usage: perl [switches] [--] [programfile] [arguments]
  -0[octal]       specify record separator (\0, if no argument)
  -a              autosplit mode with -n or -p (splits $_ into @F)
  -C[number/list] enables the listed Unicode features
  -c              check syntax only (runs BEGIN and CHECK blocks)
  -d[:debugger]   run program under debugger
  -D[number/list] set debugging flags (argument is a bit mask or alphabets)
  -e program      one line of program (several -e's allowed, omit programfile)
  -f              don't do $sitelib/sitecustomize.pl at startup
  -F/pattern/     split() pattern for -a switch (//'s are optional)
  -i[extension]   edit <> files in place (makes backup if extension supplied)
  -Idirectory     specify @INC/#include directory (several -I's allowed)
  -l[octal]       enable line ending processing, specifies line terminator
  -[mM][-]module  execute "use/no module..." before executing program
  -n              assume "while (<>) { ... }" loop around program
  -p              assume loop like -n but print line also, like sed
  -P              run program through C preprocessor before compilation
  -s              enable rudimentary parsing for switches after programfile
  -S              look for programfile using PATH environment variable
  -t              enable tainting warnings
  -T              enable tainting checks
  -u              dump core after parsing program
  -U              allow unsafe operations
  -v              print version, subversion (includes VERY IMPORTANT perl info)
  -V[:variable]   print configuration summary (or a single Config.pm variable)
  -w              enable many useful warnings (RECOMMENDED)
  -W              enable all warnings
  -x[directory]   strip off text before #!perl line and perhaps cd to directory
  -X              disable all warnings

Linked In Libraries

To find out where perl will look for modules when running your perl app you can issue the following linux command:

perl -V

On the CSL server the linked library path defaults to:

Characteristics of this binary (from libperl): 
  Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO
  Built under linux
  Compiled at Sep  4 2007 08:46:00
  @INC:
    /usr/lib/perl5/5.8.8/i686-linux
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/i686-linux
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl/5.8.7/i686-linux
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl/5.6.2
    /usr/lib/perl5/site_perl

CPAN

CPAN is a great place to obtain (or contribute) Perl Modules, shared objects that anyone can use on their system. The easiest way to install a CPAN module is to login to your shell prompt and use the cpan command found on most systems.

To install a module, and all of the modules it depends on to work, use the cpan -i command. Example:

cpan -i Image::Magick

This will fetch the specified CPAN module and all the other modules needed to make it run. If there are no "gotchas", all of the components are downloaded and installed to the shared Perl library locations on your system. From this point forward you will continue to have access to these modules whenever you need them from any application running on your server.

If you are running your site on a shared server you may need to ask your web hosting company to install specific modules for you. If they can not help you, don't worry, there are ways to install the modules locally just for your own use. They will take up some of your disk space, but usually not enough to worry about.

Bundles

Bundles are groups of CPAN modules that work well together. Often the bundles form a nearly complete applet or functional component of a complete system. The only thing that is required after installing a bundle is for you to provide some "glue" in the form of a Perl wrapper. The wrapper that you write includes a little bit of configuration and a little bit of your own "magic", then you are ready to go.

Installing a module is very similar to installing an individual module. You can search CPAN for bundle names, then install them from your Linux command line with a command like:

cpan -i Bundle::CPAN

Links

Personal tools
Cyber Sprocket Labs
Cyber Sprocket Tech