Enable Backtraces with Carp::Always (Modern Perl Tips)
Ever had a program crash and wanted to get more details about where and why? The CPAN module Carp::Always is perfect for this.
Read it
How to redirect and restore STDOUT
STDOUT is the Perl filehandle for printing standard output. Unless a filehandle is specified, all standard printed output in Perl will go to the terminal. Because STDOUT is just a global variable, it can be redirected and restored. Want to implement logging on a program without changing every print statement in the source code? Want to capture the standard output of a perl CRON job? Read on.
Read it
Find CPAN mirrors and configure the local CPAN mirror list
CPAN mirrors are online repositories which host or “mirror” the Perl module distributions on CPAN. There are hundreds of CPAN mirrors dispersed throughout the World. When the CPAN program is run for the first time on a machine, it will configure the CPAN mirror list to use for checking for new versions of modules and downloading Perl distributions. All CPAN mirrors are not created equally though: the distribution list’s age, speed and the geographic location vary from mirror to mirror and so you may want to re-configure your local CPAN mirror list to suit your needs. This article describes how to find CPAN mirrors and edit the local CPAN mirror configuration.
Read it
How to schedule Perl scripts using cron
Cron is a job scheduling program available on UNIX-like platforms. Most system commands can be scheduled including the execution of Perl programs. Once a job is setup, cron will run it as scheduled even if the user is not logged in, which can be a great way to automate sysadmin tasks or repetitive jobs. This article describes how to run Perl scripts with cron.
Read it
How to read a string into an array of characters using split
Perl’s split function has a useful feature that will split a string into characters. This works by supplying an empty regex pattern (“//”) to the split function. This can be used to easily split a word into an array of letters, for example:
Read it
Get detailed Perl version configuration information
Most Perl programmers know they can find out the current Perl version by typing “perl -v” as the command line:
Read it
Banish unsightly variable assignments with Method::Signatures
Add subroutine signatures to Perl
Read it
Perl destructor not being called? Here's why
If you’re using a Perl destructor method (‘DESTROY’, ‘DEMOLISH’) it may not be called if the Perl process is terminated abruptly by a signal. To fix this, just add the sigtrap pragma to your program:
Read it
Catch and Handle Signals in Perl
We show you how to listen for signals and handle them gracefully
Read it
Run local Perl as root
This is a simple trick for conveniently running local Perl as a root user on UNIX-based systems.
Read it
Call object methods without an object reference
Perl’s flexible syntax accepts all kinds of shenanigans and hackery. This article describes one such trick to call object methods without including the referent object (sort of).
Read it
How to track new CPAN releases
CPAN is a fantastic Perl resource with thousands of modules and new ones being added all the time. But how do you keep track of what’s being released? This article describes three techniques for keeping tabs on the latest CPAN releases.
Read it
Re-use code with Perl's anonymous functions
An anonymous function in Perl is an unnamed subroutine. But what are they good for? This article shows how through using anonymous functions it’s possible to write more generic, re-usable Perl code.
Read it
Use the logical-or and defined-or operators to provide default subroutine variable behaviour
Perl subroutines do not have signatures so variables must be initialized and arguments assigned to them inside the subroutine code. This article describes two useful shortcuts that can simplify this process.
Read it
Perl hash basics: create, update, loop, delete and sort
Hashes are one of Perl’s core data types. This article describes the main functions and syntax rules for for working with hashes in Perl.