Since the 0.29 release of perlbrew, it is much easier to invoke perlbrew
function in the shell script. Specifically the perlbrew use and perlbrew
switch commands. Here's an example bash script:
#!/bin/bash
## These 3 lines are mandatory.
export PERLBREW_ROOT=/opt/perlbrew
export PERLBREW_HOME=/tmp/.perlbrew
source ${PERLBREW_ROOT}/etc/bashrc
## Do stuff with 5.14.1
perlbrew use 5.14.1
perl /app/my-modern-program
## Do stuff with 5.12.3
perlbrew use 5.12.3
perl /app/my-legacy-program
In short: definde PERLBREW_ROOT and PERLBREW_HOME before including the perlbrew bashrc file.
In an interactive shell environment, the default value of $PERLBREW_HOME is
$HOME/.perlbrew. However, $HOME might not be always there in the context
when a script is executed. It is then mandatory for you, the programmer, to
specify a $PERLBREW_HOME that can be writable by the user running the script.
Notice, with the bash integeration, the statement perlbrew use 5.14.1 actually
invokes the perlbrew bash function instead of the command perlbrew. Previous
perlbrew release contain buggy perlbrew bash function and did not function properly.
Therefore please make sure to upgrade to perlbrew 0.29 or latter.