Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Storing filehandles in non-scalar datastructures

by mwp (Hermit)
on Dec 03, 2000 at 03:43 UTC ( [id://44605]=note: print w/replies, xml ) Need Help??


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

...like IO::File and the methods mentioned on Mark-Jason Dominus's Perl Paraphernalia site: http://perl.plover.com

In particular, check out the Seven useful uses of local article... really neat. (#3 should do the trick for you.)

'kaboo

  • Comment on Re: Re: Storing filehandles in non-scalar datastructures

Replies are listed 'Best First'.
Re: Re: Re: Storing filehandles in non-scalar datastructures
by Anonymous Monk on Dec 03, 2000 at 04:08 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? :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://44605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-24 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found