Monday 1 July 2013

Running a perl script with a particular version of Perl

If you want to use a perl script that only appeared in a particular version of perl (eg. the 'say' command, which appeared in perl 5.10), then you can specify inside the script that you can specify in the perl script that you want to use perl5.10 and that new features (such as 'say') should be enabled:

use 5.010;
say 'Hello';

Then you need to run the perl script with the correct version of perl for it to work:
% /software/perl-5.10.1/bin/perl -w

Note that if you don't use the correct version of perl, you'll get an error message:
% perl -w
Perl v5.10.0 required--this is only v5.8.8, stopped at line 3.
BEGIN failed--compilation aborted at line 3.

Note also that if you don't include the "use 5.010" in your script, it won't enable new features specific to 5.010 by default, and you'll get an error message because the 'say' command won't be recognised:

say 'Hello';

% /software/perl-5.10.1/bin/perl -w
Unquoted string "say" may clash with future reserved word at line 3.
String found where operator expected at line 3, near "say 'Hello'"
    (Do you need to predeclare say?)
syntax error at line 3, near "say 'Hello'"
Execution of aborted due to compilation errors.

No comments: