tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ GDBM_File barfs on NFS mounted disk

Directory name extraction ▻

Piping array contents to a system command

In article <4eoncd$d7m@news.tamu.edu>,  <Ron> wrote:
>Currently in a perl script I am setting the contents of an array
>from a system command as follows:
>    $output = `command < file`;
>What I would like to do is to have the command get its input from
>array instead of the file, that is I would like to pipe the contents
>of an array to the command.

This is a mildly disguised version of question 5.14 in the FAQ:
"How do I open a pipe both to and from a command?".  In summary,
it's difficult or impossible to do this right.

The simplest options would be i) to write the array to a temporary
file first (not forgetting to close it before you run the command);
or ii) to split the program into the bit that generates the array,
and the bit that processes $output, and join them all together with
`command' in a pipeline.

Tim.
--
Tim Goodwin   | "Forget the mystical level numbers." -- Henry Spencer

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: Piping array contents to a system command
Date: 1 Feb 1996 17:32:19 GMT
Organization: Unipalm PIPEX
Message-ID: <4eqtf3$2pp@wave.news.pipex.net>
References: <4eoncd$d7m@news.tamu.edu>

△ comp.lang.perl △

◅ GDBM_File barfs on NFS mounted disk

Directory name extraction ▻