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

Re: Unexpected behavior of function 'say'

by LanX (Chancellor)
on Mar 05, 2013 at 15:24 UTC ( #1021847=note: print w/replies, xml ) Need Help??


in reply to Unexpected behavior of function 'say'

hmm not in 5.10

lanx@nc10-ubuntu:~$ perl use strict; use warnings; say STDOUT 'like a charm'; Can't locate object method "say" via package "IO::Handle" at - line 4.

But the last line should lead to the answer.

print FH is (supposed to be) indirect object syntax of the filehandle-object, so somehow the method say was activated by default in your environment.

Anyway calling say w/o FH shouldn't work!

Cheers Rolf

Replies are listed 'Best First'.
Re^2: Unexpected behavior of function 'say'
by tobyink (Abbot) on Mar 05, 2013 at 15:32 UTC

    This is because of a change in Perl 5.14:

    Filehandle method calls load IO::File on demand

    The OP's code does work in Perl 5.10, if you run it with the -MIO::Handle parameter to manually load the IO::Handle package.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      So print FH was magic in doing so prior to 5.14?

      I hate breakes in symmetry...

      BTW: I checked IO::Handle , it's a normal method and features aren't checked.

      sub say { @_ or croak 'usage: $io->say(ARGS)'; my $this = shift; local $\ = "\n"; print $this @_; }

      Cheers Rolf

        The point of the feature is to avoid to break existing function calls. Without feature, the code the OP posted is still the very same method call as it was before 5.10, so everything is working as it should.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021847]
help
Chatterbox?
[atcroft]: Lady_Aleena: My early code was pretty horrible... but somewhere early on I learned not to take criticism of my code personally... which was probably a good thing, considering the kind of code I wrote at the time. :\
[Lady_Aleena]: I am hungry, so I'm going to go make something to eat. I hope you figure it out atcroft. Have a nice night!
[atcroft]: I have one script that I have started re-writing several times over the years, and have yet to get it working in a cleaner/better form. (It is some smelly code-I did not even know about hashes at the time I wrote it.)
[atcroft]: Enjoy, Lady_Aleena!

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-05-27 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?