[Israel.pm] integrating unix commands

Yuval Kogman lists at woobling.org
Wed Jan 14 05:50:14 PST 2004


On Wed, Jan 14, 2004 at 10:48:30AM +0200, Offer Kaye wrote:

> $|=1; for(`command`){do_stuff} ?

No.. That won't work. It will simply do the command again and again.

> > Another aspect of flexibility is when you process - with pipes you can
> > do stuff with the output as it happens - so the output needn't be
> > finite.

> Lost me there, it looks like the first point to me. Can you elaborate?

I will not rephrase but rather emphasise, because it just hit me how
vague that was...

Another aspect of flexibility is /when/ you process

I mean that you don't need to wait till the pgoram finishes - it never
needs to finish. As data comes out of it, you get it, in as small
chunks as it flushes.

> I personally have been burned by the lack of portability when using
> redirection operators, so I can agree with this point.

BTW, i'm not 100% sure on this (have never, ever, in my whole life
actively worked on windoze), but i think windoze, at least some semi
sane variant of the NT family, has pipes too.

> I'm pretty sure this statement is not correct (I mean about the merged
> output or only one FD). Specifically you can do a crazy thing like:
>    $output = `cmd 3>&1 1>&2 2>&3 3>&-`;

which brings me to another aspect -

code readability. This will drive a newbie, or an experienced
programmer deprived of posix, mad.

A filehandle for each output of the program is somewhat more obvious.

> I wonder how you would do the above with pipes, though?

You would simply get individual filehandles for both and do what you
want with them. No need to swap since you get everything out.

BTW, if you want to use numbered FDs, the POSIX module is a bit of
fun, and you can do funny things with what you pass to open.

-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me whallops greyface with a fnord: neeyah!!!!!!!




More information about the Perl mailing list