Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

about "say" function

by lightoverhead (Monk)
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

Thanks.

Comment on about "say" function
Download Code
Re: about "say" function
by kennethk (Monsignor) 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.

      kennethk

      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 (Deacon) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1097147]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-27 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls