Jupiterhost.Net wrote: > > #!/usr/bin/perl > > use strict; > use warnings; > > my $howdy = 'hello'; > push(@ref_to_destroy, \$howdy); > for(@refs_to_destroy) { > my $r = ref($_); > if(defined $r) { > close $_ if $r eq 'IO'; > undef $_ if $r eq 'SCALAR'; > } > } > print "I still have howdy -$howdy-\n" if defined $howdy; > > > If I do undef ${ $_ } if ... then it works (IE you get no "I still > have" message.. > Which means I have to do @{ $_ } %{ $_ } etc also... The etc part is the > one throwing me now :) >
i am little confuse, do you want to loose the ref $howdy is pointing to so Perl can gc the ref or undef $howdy itself if $howdy is a ref? your method dereference $howdy first and then undef whatever it's pointing to. you can look at it like: $howdy -> $ref -> $scalar your undef ${$howdy} basically means: $howdy -> $ref $scalar which breaks the ref from $ref to $sclar but $howdy is untouched. for example: [panda]# perl -le '$_=\\$.; undef $$_; print "r" if ref $_' r [panda]# notice $_ is still a ref but if you do: [panda]# perl -le '$_=\\$.; undef $_; print "r" if ref $_' [panda]# nothing is print because you end up with: $_ $ref -> $scalar now if $ref and $scalar has no more reference, Perl can gc them. your version ends up: $_ -> $ref $scalar and if $scalar has no more reference, Perl can gc it but Perl can't gc $ref because $_ still points to it. if you don't want the undef-ness of my version, you can always: [panda]# perl -le '$_=\\$.; $_ = 0; print defined $_' 1 [panda]# so that after you loose the ref, $_ is still defined. finally, notice your undef $$_ is also bugous: [panda]# perl -e '$_ = \\1; undef ${$_}' Modification of a read-only value attempted at -e line 1. [panda]# you don't want that do you? :-) at the end, it's your call and it depends on how you set up your ref and what you want to do with it. david -- s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$ \x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65 \x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72 \x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32 \x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74 \x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>