Perl quick start

Installation

I use ActivePerl on Windows.  After installing Perl, open up a cmd prompt.  Execute cpan.bat from  c:\Perl\bin or the bin directory of where ever you installed Perl.  This will install the c compiler for you.

To install modules from CPAN, run cpan from  command prompt.  Type in install module name from cpan’s shell prompt.  the module name is case sensitive. (example:  cpan>install String::Util)

If Komodo edit have problem finding the installed perl intepreter,  add the path to perl at the front of edit->preference->environment->classpath.

If using ActivePerl, you can use ppm to see all installed modules.  It comes with a good set.  Just type ppm at the command prompt.

To expand @INC to include extra directories containing packages you have downloaded from CPAN:  Set user variable PERL5LIB to the path containing the packages (control panel->set environment variables).

Most of this stuff is in the Impatient Perl guide

String Concatenation:

$name = checkbook'; 
$filename = '/tmp/' . $name . '.tmp';

if, elsif, else, unless

http://perlmeme.org/howtos/syntax/ifelsifelse.html

File Operations:

open(my $filehandle, 'filename.txt')
or die "Could not open file";

 

close($filehandle) or die "Could not close";

Conditional Operator

my $RESULT = $BOOLEAN1 ? $VALUE1 : $VALUE2;

Problem printing newline in Windows or to notepad compatible files

append print statement with chr(012).chr(015). This prints ASCII for CRLF.  If you are using different char set, use the equivalent octal value from the char set.  Note, this does not work in PHP.  Use PHP_EOL if “\n” doesn’t work in print.

 

Variable Declaration

The variables $a and $b are special variables used in the sort function of Perl and, for historical reasons, are exempt from the requirement to declare them.

 

Good link to Perl Regex

http://perldoc.perl.org/perlrequick.html#Search-and-replace

Bar Code generations:

Use CODE128 specification and PerlMagick.  GD::Barcode is also a good staring point.

Win32::OLE

Good link from Microsoft: http://support.microsoft.com/kb/214797

Good example link: http://www.perlmonks.org/?node_id=153486

Good example of basics:  http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.40/examples/win32ole.pl

Win32::UTCFileTime

Good time module to use on Windows.  Default time module seems to have the year stuck at 1969 for some reason.

Multi-line Comments

=for comment
bunch of code to be commented out

=cut

Good Perl Array Link

 

Comparing arrays

 

Break out of a loop:

last