Will this script run under the Perl version available to the customer?
tyler@inspiron:~$ perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
I have found that Perl 5.8.x is the most common distribution available on all servers I have worked with. So, how to make sure the code I write will not break on a 5.8.x Interpreter?
Perlbrew.
It is a great tool that essentially lets you swap one Perl version for another! With one command, the default perl interpreter can be changed to another version, and I proceed with development with an environment that very closely matches that of the customer.
tyler@inspiron:~$ perlbrew switch perl-5.8.5
Perlbrew is available off of CPAN.
Perlbrews real strength however, is the ability to have it manage installing other Perl versions for you. Did you notice I only have Perl version 5.10.1? Well, with a simple
tyler@inspiron:~$ perlbrew install perl-5.12.2 ...... Installed perl-5.12.2 as perl-5.12.2 successfully. Run the following command to switch to it. perlbrew switch perl-5.12.2
and approximately 20 minutes later, I'm much more up-to-date.
What Modules can I use for the work?
Corelist available also at CPAN.
I think some sample command lines help illustrate the usefulness of this module. It takes one argument, a module name an answers the question: "Is this a core module, and if so, since which version?"
tyler@inspiron:~$ corelist XML::Parser XML::Parser was not in CORE (or so I think)tyler@inspiron:~$ corelist Test
Test was first released with perl 5.00405tyler@inspiron:~$ corelist HTML::Template
HTML::Template was not in CORE (or so I think)tyler@inspiron:~$ corelist File::Copy
File::Copy was first released with perl 5.002tyler@inspiron:~$ corelist version
version was first released with perl 5.009tyler@inspiron:~$ corelist CGI
CGI was first released with perl 5.004tyler@inspiron:~$ corelist FileHandle
FileHandle was first released with perl 5tyler@inspiron:~$ corelist Pod::Html
Pod::Html was first released with perl 5.004
Thank you for reading!
]]>I like to use an iterative method of programming. Code some lines, execute and test. Rinse and repeat. But I found my method of debugging annoying. $\ = "\n"; and print() statements to sanity check my variables, only to delete or comment those lines later.
Enter a great Module: Devel::Comments A module to help with debugging in the development stage by using the comment lines in your scripts.
Make the comments in your code work for you. Now to view the value of a variable: write:
### $mainDirectory
and STDERR will print out:
### $mainDirectory: /home/tyler/perl
You can set different output channels when you use the Module, or a combination of them (STDOUT and a filehandle). Best of all, when you are done the development work, you can simply remove the 'use Devel::Comments' line or comment it out, and all debug statements are disabled at once. The number of # characters you use determine the debug level, and different levels can be enabled or disabled for use.
Two final things: Assertions and checks are available too, that will act as a warn and die if the boolean checks fail.
### insist: $divisor != 0 (the assert statement)
### check: $current_year > 1900
This Module has proven to be much more helpful than the print statements that I once used when creating small scripts for my personal use. I use much more formal debugging and logging methods for applications I release, such as Log::Log4Perl.