in reply to Re: Re: Storing filehandles in non-scalar datastructures
in thread Storing filehandles in non-scalar datastructures

Okay, trying that method: $$LOG{$_}[0]=do {local *FH;}; both of these lines:
print $$LOG{$_}[0]; print scalar <$$LOG{$_}[0]>;
return:
*main::FH

Replies are listed 'Best First'.
(an example) Re (4): Storing filehandles in non-scalar datastructures
by mwp (Hermit) on Dec 03, 2000 at 16:15 UTC
    Try this:
    #!/usr/bin/perl use strict; # create data structure my $LOG = {}; $LOG->{A} = []; # $LOG->{A}[0] is the same as $LOG->{A}->[0] # is the same as $$LOG{A}->[0] # create anonymous file handle $LOG->{A}[0] = do { local *FH }; # open file for writing, assign to anon file handle open($LOG->{A}[0], ">dummy.txt") || die "Unable to open test file."; # unable to print directly to the pointer, so we select it instead select($LOG->{A}[0]); print <<EOF; This is a test of the anonymous file handle procedure. Were this an actual, real-life procedure, instructions would follow this message. EOF # we're done, go ahead and close the sucker close($LOG->{A}[0]);

    Ya with me? :)