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

Hi monks, I have taken a reference of a glob using qualify_to_ref, where the glob was actually created by gensym method, now I have two references pointing to the same typeglobs, how do I remove the actual glob created by gensym using the reference created by quality_to_ref. I have checked using undef, but it removes only one typeglob. how to remove both. sample code
use Symbol; $a = gensym; $b = qualify_to_ref $a; undef $a; # This works # how to remove $a via $b print "A>",$a ,"<\n"; print "B>",$b ,"<\n";
could you guide me!

Replies are listed 'Best First'.
Re: How to remove the actual glob from a glob reference
by dave_the_m (Monsignor) on Oct 04, 2008 at 15:56 UTC
    now I have two typeglobs pointing to same address

    No, you have two references pointing to the same (ie a single) typeglob. undef $a causes one of the references to the typeglob to be freed (the typeglob itsself is not yet freed, since $b still contains a reference to it).

    If in addition you do undef $b, then the typeglob will be freed. But it's not clear to me what you are actually trying to achieve.

    Dave.

      Thanks for your comments and yes I got your point, I know that undef $b will do, But I need to delete $b using $a, The typeglob itself need to be freed via $a without actually using $b. Have you got it now?.
        Thanks for your comments and yes I got your point, I know that undef $b will do, But I need to delete $b using $a, The typeglob itself need to be freed via $a without actually using $b. Have you got it now?.
        "delete $b using $a" doesn't make much sense. Do you want to delete the reference $b (leaving the typeglob it refers to unchanged), or do you want to delete the typeglob itself?

        You cant delete the typeglob while a reference to it still exists (from $a or $b). You can however make it undefined, (freeing up any IO handles etc attached to it) with the following:

        undef *$a

        Dave.