Symbol removal puzzle 
Author Message
 Symbol removal puzzle

I am looking for a reliable way of removing a particular symbol from a
particular package.  Various things that work in one version on Perl
sometimes don't in another, and my attempts to investiage have let to
puzzle after puzzle.

Here is one, which I hope someone will explain to me.  It is an
experiment with two possible idioms for removing a symbol from a
package.  One tries to use `undef' on the glob, and the other tries to
use `delete' to remove the name from the symbol table.

        $x = 10;
        $v = 5;

        delete ${'::'}{'x'};
        undef *{'::v'};

        print "x=$x; v=$v\n";   ####

        undef *{'::x'};

        print "x=$x; v=$v\n";   ####

Under 5.005_02, the first print statement prints

        x=10; v=

which suggests that the `undef' idiom did remove the variable, but the
`delete' idiom did not.  But the second line *also* prints

        x=10; v=

which shows that the `undef' syntax only works if you *haven't* tried
to use `delete' first.  

I hope someone can explain why this is, and also answer my original
question, which is how to remove a symbol from a package in a reliable
way that will work with as many versions of Perl as possible.  Neither
of the two idioms above works in 5.004_04, for example.




Sat, 10 Nov 2001 03:00:00 GMT  
 Symbol removal puzzle
[A complimentary Cc of this posting was sent to Mark-Jason Dominus


Quote:

> I am looking for a reliable way of removing a particular symbol from a
> particular package.

You cannot.  

Hope this helps,
Ilya

P.S.  See

Quote:
> perl

$a = 11;
delete ${'::'}{'a'};
${'a'} = 17;
print "'$a', '${'a'}'.\n";
^Z
'11', '17'.


Sun, 11 Nov 2001 03:00:00 GMT  
 Symbol removal puzzle

Quote:

>I am looking for a reliable way of removing a particular symbol from a
>particular package.  Various things that work in one version on Perl
>sometimes don't in another, and my attempts to investiage have let to
>puzzle after puzzle.

[snip]

Quote:
>    $x = 10;
>    $v = 5;

>    delete ${'::'}{'x'};
>    undef *{'::v'};

>    print "x=$x; v=$v\n";   ####

>    undef *{'::x'};

For me, changing the above to
        undef *x;

works.  What clued me into that is a "use diagnostics" message
from something else I tried.

Of course, dont take that to mean I actually understood what's
going on!  For instance, why should that be different from your
statement?  On  first look I'd have thought they're almost the
same (except the first one looks like a symbolic ref).

There - that last line ought to get Tom involved ;-)

I guess I have to re-read my panther - and this time not skip over
the "my eyes glaze over" parts :-)



Mon, 12 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Solaris DB_File.so: symbol dbopen: referenced symbol not found

2. comp.lang.perl.moderated, FINAL NOTICE of Newsgroup Removal

3. Bidirectional filter: hair removal begins...

4. MS Word metadata removal

5. Removal or HTML tags from pages

6. Removal of newline characters

7. Removal of duplicate entries from mutidimentional arrays

8. Regular expression for stopword removal

9. here file leading space removal

10. comp.lang.perl.misc, FINAL NOTICE of Newsgroup Removal

11. Trailing string removal

12. Safe temp file removal

 

 
Powered by phpBB® Forum Software