Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I'm fully prepared for a 'read the docs you bonehead' response, but I'm stumped :)

Say I have a class Foo, and I say
my $foo = new Foo; my $foo = new Foo;
Then, when it goes to destroy $foo, it bitches about DESTROYs and other gripe. In the Camel book there's some stuff about re-blessing, but my eyes glaze over just a tad - can anyone explain?

Replies are listed 'Best First'.
(jeffa) Re: OO confusion
by jeffa (Bishop) on Jan 21, 2001 at 10:04 UTC
    The only thing I see wrong is your re-my-ing your class. You should't do that. Instead you should use:
    my $foo = new Foo; $foo = new Foo;
    you should be getting a warning - are you using the -w switch?

    Also, you should submit the errors that are being generated, as well as what is going on inside a Foo.

    Jeff

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: OO confusion
by chromatic (Archbishop) on Jan 21, 2001 at 10:06 UTC
    You'll have to paste more code. I used the following and it works perfectly (removing the second spurious my, which doesn't work):
    #!/usr/bin/perl -w use strict; package Foo; sub new { bless({}, $_[0]); } package main; my $foo = new Foo; $foo = new Foo;
Re: OO confusion
by extremely (Priest) on Jan 21, 2001 at 12:33 UTC
    We need to see the package Foo code. You've likely got something in there that is jumping between objects.

    --
    $you = new YOU;
    honk() if $you->love(perl)

A reply falls below the community's threshold of quality. You may see it by logging in.