in reply to Re^6: Is it ok to mix functional and oo programming in one package?
in thread Is it ok to mix functional and oo programming in one package?

Ah, but wait, you didn't write
hello $a;
Why's that? It works ;-)

But when there's a hello sub in package main, then _that's_ the one that gets called, so it's not as if the advice is completely unjustified.

#!/usr/bin/perl use warnings; use strict; package Foo; sub new { return bless {},shift; } sub hello { print "hello"; } package main; sub new { print "haha"; return; } sub hello { print "Hi, $_[0]!"; } my $a = new Foo; hello $a; __END__ Hi, Foo=HASH(0x814bd48)!

Replies are listed 'Best First'.
Re^8: Is it ok to mix functional and oo programming in one package?
by BrowserUk (Patriarch) on Oct 19, 2007 at 11:34 UTC
    Ah, but wait, you didn't write hello $a;

    True, but when I have an object instance, invoking instance methods using direct method invocation is, well, natural. I'd never think to do it any other way. But class methods on a bare-word...


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.