in reply to Object singleton method

Of course it's possible! There's even a module on CPAN to do it: Class::Singleton.

However, a singleton is really more of a design pattern, so there's a lot of ways to implement it. Rolling your own isn't that hard:

package MyClass; my $instance; sub get_instance { unless ($instance) { $instance = ...; # instantiate instance here } $instance; }

Replies are listed 'Best First'.
Re^2: Object singleton method
by sh1tn (Priest) on Jun 19, 2008 at 23:25 UTC
    The example is another pointer to Class singleton method and not instance one. All I wanted is:
    s = String.new "s" def s.singleton print "ok" end # later on s.ok