Im trying to learn Perl, am using OS-X 10.8.4 and have Perl version:
This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level
I am trying to run this code:
#!/usr/bin/env perl
use strict;
use warnings;
my $a = 1;
my $b = 1;
say $a + $b ;
And I am getting this:
Can't call method "say" without a package or object reference at test2.pl line 10.
Thanks!
say
is a new feature, added in Perl 5.10. In order to not break old code, it's not available by default. To enable it, you can do
use feature 'say';
But it's probably better to do
use feature ':5.12';
which will turn on all new features available in Perl 5.12 (the version you're running). That includes the say
, state
, switch
, unicode_strings
and array_base
features.
See the feature
documentation for what each of those does.
You need to use feature qw (say);
The documentation for say
.
Modern::Perl is a great package on CPAN that turns on functions in modern versions of perl as well as pragmas like warn and strict that (imho) all perl programmers should use. All my programs start this way now:
use Modern::Perl '2013';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With