Jupiterhost.Net wrote:

>
>> Ok, well you think that might have helped to state in the first place,
>> especially when posting to a beginners list?
> 
> Sorry I didn't mean to offend anyone, I felt it was irrelevant to the
> question. (IE - How do I vacuum my car instead of How would I vacuum a
> blue car?)
> 

no need to apologize, you didn't offend anyone. i read the thread and i 
agree with you that your question of how to undef a ref is irrelevant to 
how you manage a persistent process via PersistentPerl or FCGI or mPerl.

>
> I simply was trying to figure out the best way to undef/close/other wise
> destroy each ref in a list of refs depending on the type of reference. I
> figured the way I was doing it didn't matter because either way all I
> want to do is:
> 
> undef ${$_} if ref($_) eq 'SCALAR';
> I can do the above for SCALAR, ARRAY, HASH
> but the question is what do I do if it's one of these:
>   IO, GLOB, or CODE
>

no need to do that, you don't want to undef what $_ points to, you want to 
undef $_ itself. for example:

#!/usr/bin/perl -w
use strict;

$_ = {a => b => c => 1};

undef %{$_};

print "still a ref\n" if ref $_;

__END__

prints:

still a ref

simply:

* undef $_ is fine
* in fact, you can loose a reference count (Perl uses reference counting to 
gc) by simply pointing $_ to somewhere like:

$_ = 1;

in turns of ref to IO, you can do similiar like:

#!/usr/bin/perl -w
use strict;

sub decrease_ref_count{
        my $r = ref $_[0];
        return unless $r;
        close $_[0] if $r =~ /IO/;
        undef $_[0]; #-- or $_[0] = 0;
}

$_ = *STDIN{IO};

decrease_ref_count($_);

1 while(<STDIN>); #-- STDIN already closed

__END__

> 
> 1) Are there any other ref() type's I am missing?
>

yes. ref to ref or ref to objcts etc, consider:

$_ = \\1;

print ref $_,"\n"; #-- prints REF

but the inner ref is lost when you loose the outer ref.

> 2) If the reference is to an open file handle (\*FH):
>   a) it will ref() as a GLOB correct (or IO)?

it will be a GLOB is it's GLOB and it will be an IO if it's an IO, depends 
on how you set up your ref:

print ref \*STDIN,"\n";    #-- GLOB
print ref *STDIN{IO},"\n"; #-- IO::Handle

be sure to write code that handles both

>   b) Will it be closed if I handle it like any other GLOB or do I need
> to somehow check if its an open filehandle and close it?

i would check for IO and close it if needed

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>


Reply via email to