open() and pipes

Uri Guttman uri at stemsystems.com
Wed Aug 2 16:54:22 BST 2006


>>>>> "DC" == David Cantrell <david at cantrell.org.uk> writes:

  DC> On Tue, Aug 01, 2006 at 12:31:08PM -0400, Uri Guttman wrote:
  >> David Cantrell <david at cantrell.org.uk> writes:
  >>> I know that you can't do this ...
  >>> open(FOO, '|program|')
  >>> It just seems odd to me that this functionality is missing and that you
  >>> need to use a module for it.  Given that IPC::Open2 was bundled with the
  >>> very first version of perl5, it seems odd that that functionality wasn't
  >>> just rolled into open() at that time.
  >>> Am I missing something obvious?
  >> yes, 1 handle vs 2.
  >> 
  >> open only takes one handle for an argument and pipe needs two handles
  >> (for parent and child after forking).

  DC> But FOO isn't really a handle.  It's some kind of magic data structure
  DC> which gets internally resolved to a filehandle.  I can see no reason why
  DC> it couldn't point at seperate *real* filehandles for reading and
  DC> writing.

FOO is a typeglob which refers to a special structure which has a single
handle slot along with scalar, array, hash and a few other slots. so it
can't make that into 2 handles. if you use a typeglob where a handle is
expected the handle slot is used. you can make a ref to that handle slot
with the *FOO{IO} syntax but only 1 handle can be stored there (not
counting the dir handle). so even if you could store 2 handles there is
no syntax to access both of them separately to do reading and writing.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


More information about the london.pm mailing list