nowox
nowox

Reputation: 29096

How to tell Perl to always run with use v5.010?

When I write small programs or oneliners I cannot use say. I always need to put:

#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

In oneliners I can simply do perl -E "say 'toto'" but in regular programs I don't know how to do it...

Any idea?

Upvotes: 0

Views: 371

Answers (3)

cjm
cjm

Reputation: 62099

Use an editor with a template or macro system to insert the boilerplate when you start a new file. For example, Emacs has skeleton.el and tempo.el (plus numerous other packages you can install).

Upvotes: 1

Borodin
Borodin

Reputation: 126722

You could set the default perl command-line options using the PERL5OPT environment variable

PERL5OPT=-M5.010

or, more safely

PERL5OPT=-Mfeature=say

Upvotes: 5

LeoNerd
LeoNerd

Reputation: 8532

This is verymuch by design. When perl is reading a program from a file, it remains in back-compatibility mode, so that older programs are not broken by features added in later versions. By saying

use 5.010;

you are saying you want at least 5.10, and thus it turns on all the features that were present in that version. This ensures that a file lacking such a declaration will not be confused.

Upvotes: 4

Related Questions