PERL - Practical Extraction and Report Language

This is a scripting language that can accomplish all kinds of neat things. The official website is http://www.perl.com .

Before you go ahead a write a new program in Perl, checkout the Comprehensive Perl Archive Network . Hundreds of modules are freely available for Perl to integrate with different APIs, and very rarely would you need to develop a new one. The CPAN Frequently Asked Questions contains quick answers to many general questions about modules.

Subroutines

Methods or functions in perl can be done using the sub keyword


sub print_hello {
  print "hello\n";
}

After defining the subroutine you can call it using print_hello()

To pass a parameter you can use shift


dump_stats(11);

sub dump_stats {
	my $hour=shift;
  ....
}

The the local var $hour, will have the value of 11.

String matching

Use =~ to test if a pattern matches a string variable.


     if ($foo =~ /bar/) {
       print "The variable foo matches bar";
     }