Kudos to documentors: (popen2)

Tom Christiansen tchrist at mox.perl.com
Thu Aug 19 19:08:32 CEST 1999


     [courtesy cc of this posting mailed to cited author]

In comp.lang.python, 
    Robb Shecter <shecter at darmstadt.gmd.de> writes:
:It ought to be.  Or at least, well-linked "info" pages.  (This is
:surely easily agreed upon, right?)  

You'd be surprised.

But this is a moot issue, because:
:>     man IPC::Open2
:...has apparently the same text that bothered me.  
:
:
:1)  It will not create these file handles for you.  You have
:       to do this yourself.  So don't pass it empty variables
:       expecting them to get filled in for you. 

:
:My question: how do I create these file handles?  What document would
:I look in to find out?  

Normally you just use them, as in

    open2(FH1, FH2, "cmd here")

and they appear as globals in your package namespace (that's module
namespace in python parlance).  People don't usually create anon handles.
They can be localized to a scope, though, as in this excerpt from the
perldata manpage:

       sub newopen {
	   my $path = shift;
	   local *FH;    # create new filehndle
	   open   (FH, $path) or  return undef;
	   return *FH;
       }
       $fh = newopen('/etc/passwd');

Which might suffice for your purposes.  Filehandles are not very nice in
Perl as some level.  There are object-oriented modules like IO::Handle
and IO::File, but these are just syntactic saccarine that come at a cost
of 10-100x normal built-in operations, and so they're eschewed by all
except that OO zealouts.  They do let you do

    use IO::Handle;
    $rdr = IO::Handle->new();
    $wtr = IO::Handle->new();

Which is less mysterious than the cheap and fast way:

    $rdr = do { local *FH };
    $wtr = do { local *FH };

You're correct that the documentation for the module is very sparse,
and assumes that you know this.

--tom
-- 
    "If ease of use is the highest goal, we should all be driving golf carts."
    	--Larry Wall




More information about the Python-list mailing list