Friday, May 15, 2015

Data containers and basic operations

Data containers:

Perl has three basic type of variables i.e data containers:

1. Scalar:   simple variable which holds only one value. The value can be either integer, float or string. Syntax of using a scalar is following:

my $int_var = 10;
my $ float_var = 5.9;
my $str = 'This is a string value';

2. Array:  can hold a list of values. Values can have different types i.e integer, float or string. Syntax of using an array is following:


3. Hash: is a set of key value pairs. Syntax of using an hash is following:

Executing a perl script

Perl is interpreted and like c, c++ and java, it doesn't get compiled to any native object code or byte code. A Perl script is just a text file and it is directly taken and executed by perl interpreter. 

On Unix, the Perl interpreter is called "perl". Syntax of running perl script on unix is following:  

$ perl my_first_script.pl
 

Multi-pass functioning of perl interpreter:

The interpreter does whole operation in multiple passes. In first pass it analyze the file for any syntax errors.  In second pass it runs the Perl code.  

No 'main' function:

There is no "main" function -- the interpreter just executes the statements in the file starting at the top.

Making a perl script executable:

Following the Unix convention, the very first line in a Perl file usually looks like this...
#!/usr/bin/perl -w
 

This special line is a hint to Unix to use the Perl interpreter to execute the code in this file. The "-w" switch turns on warnings which is generally a good idea. In unix, use "chmod" to set the execute bit on a Perl file so it can be run right from the prompt...
> chmod u+x foo.pl  ## set the "execute" bit for the file once
>
> foo.pl     ## automatically uses the perl interpreter to "run" this file

The second line in a Perl file is usually a "require" declaration that specifies what version of Perl the program expects...
#!/usr/bin/perl -w
require 5.004;
 

Perl is available for every operating system imaginable, including of course Windows and MacOS, and it's part of the default install in Mac OSX. See the "ports" section of http://www.cpan.org/ to get Perl for a particular system.

Tuesday, May 5, 2015

About Perl



Perl is a free, platform independent, open source programming language which is mainly used for scripting.  Lot of people contribute in perl by modules, documentation, sample code, and a thousand other useful things. Following websites for good resources:


Useful Perl modules and libraries:


1. XML::LibXML


Perl Resources:


1. (CPAN), http://www.cpan.org/ 

2. (PERL Own Website) http://www.perl.com/ 
2. (PERL Monks) http://www.perlmonks.org/ 
4. (PERL Maven) http://perlmaven.com/perl-tutorial

Good Perl References: