Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

about "say" function

by lightoverhead (Pilgrim)
on Aug 12, 2014 at 16:49 UTC ( [id://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.

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.

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

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found