Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

about "say" function

by lightoverhead (Pilgrim)
on Aug 12, 2014 at 16:49 UTC ( #1097147=perlquestion: print w/replies, xml ) Need Help??
lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:

I may have a silly question.

I tried to directly use "say" function of perl without declaring "use v5.1x".

What should I do to achive this? Why the "say" function cannot be directly used?

my perl is:

This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-gnu-thread-multi


Replies are listed 'Best First'.
Re: about "say" function
by kennethk (Abbot) on Aug 12, 2014 at 16:57 UTC

    The say function is not imported into the main namespace (Packages) by default. The shortest chain to importing it is via the feature pragma: use feature 'say';. say was implemented in Perl v5.10, but if it was imported by default, there would be the risk of backward compatibility problems and spurious warnings for perfectly fine old code. Alternatively, you can use say without importing it by giving the full package: CORE::say();.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


      Thank you for your prompt response. Actually, I have been wondering why "say" was not imported be default if this is a better feature and upgrade. Similar situations for smart comparision operators...

        For backwards compatibility with program/modules that have a sub/method called say.

        You do not need to enable a feature to use the smart match operator. You do for given and when, though, for the same reason as say.

Re: about "say" function
by aitap (Curate) on Aug 12, 2014 at 17:18 UTC
    Adding to the previous answer, you can use -E flag to use say (and all other features) in your one-oners.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1097147]
Approved by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-07-21 12:07 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (448 votes). Check out past polls.