Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do i have to specify "use feature :5.1x" even when my installed perl is 5.14?

Tags:

perl

I have 5.14.2 installed in my machine but when i try to execute a print statement with say keyword it gives me error.

I have go with the use keyword to make the program run without error.

#!/usr/bin/perl
use feature ':5.10';
say "hello";

5.14.2 is latest when compared to 5.010 so it should have all those features enabled by default right ? then what is the point in specifying the version using use keyword ?

like image 772
chidori Avatar asked Feb 24 '13 16:02

chidori


2 Answers

Perl attempts to maintain backward compatibility. It's quite possible that existing scripts might have subroutines named say. There is considerable on-going discussion of whether or not some future version of Perl should stop these efforts and streamline its internals. See, for instance, naming and numbering perl .

like image 197
JRFerguson Avatar answered Sep 19 '22 03:09

JRFerguson


It prevents conflicts with existing programs written in Perl.

For example, say I wrote a program for Perl 5.6 which defined a subroutine called say.

use strict;
use warnings;
sub say { print 1; }
say();

That works fine (outputting 1), and it still works in perls that include the say feature.

Now let's enable the native say and see what happens:

use v5.14;
use strict;
use warnings;
sub say { print 1; }
say();

Now it falls over with *Use of uninitialized value $_ in say at - line 5.*

You need to use feature or use v5.xx so that the new features can be loaded safely, i.e. when the author knows he wants to use them.

like image 25
Quentin Avatar answered Sep 22 '22 03:09

Quentin