in reply to Storing filehandles in non-scalar datastructures

use FileHandle will permit you to call $handle->readline and $handle->print(@list). And there are other ways.

-- Randal L. Schwartz, Perl hacker


update: Sorry, that should be getline not readline.

Replies are listed 'Best First'.
Re: Re: Storing filehandles in non-scalar datastructures
by mwp (Hermit) on Dec 03, 2000 at 03:43 UTC
      Okay, trying that method: $$LOG{$_}[0]=do {local *FH;}; both of these lines:
      print $$LOG{$_}[0]; print scalar <$$LOG{$_}[0]>;
      return:
      *main::FH
        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? :)

Re: Re: Storing filehandles in non-scalar datastructures
by Anonymous Monk on Dec 03, 2000 at 03:52 UTC
    Well calling readline ( ->readline() ) doesn't seem to work (Can't locate auto/FileHandle/readline.al in @INC). And niether does <$$LOG{$_}[0]>, but I think that's because I'm not using a scalar.
Re: Re: Storing filehandles in non-scalar datastructures
by Anonymous Monk on Dec 03, 2000 at 04:15 UTC
    Woo Hoo!! getline did it... thanks for all your help guys.