Reputation: 29096
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
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
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
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