in reply to Is it possible to use the open( ) function with piped unix commands?

It works just fine from perl. Your problem probably is that uniq only works on sorted lists, i.e. you want
open(LIST, "| sort -n| uniq");
and also, you need to explicitly close the LIST handle to make sort the whole pipe stop (update: i don't really know why you need to, but this code doesn't work without the close() statement ):
perl -e'open F,"|sort|uniq"; print F "aa\n","bb\n","aa\n","bb\n"; clos +e F'
output:
aa bb

Replies are listed 'Best First'.
Re^2: Is it possible to use the open( ) function with piped unix commands?
by runrig (Abbot) on Jul 19, 2007 at 00:01 UTC
    And most sort's have a "-u" option so you don't need to use "uniq".
Re^2: Is it possible to use the open( ) function with piped unix commands?
by ikegami (Patriarch) on Jul 19, 2007 at 14:44 UTC

    On perl's side, closing the file handle flushes the data and releases the process (does a waitpid).

    On sort's side, the closed input tells sort it's done receiving data so it can proceed to sort and print it.

      Yes, but I assumed that perl would close F at end of script, flushing the buffers. Instead, without the close() statement, the program just waits.

      After some more testing, it appears that I got confused. Perl does close the pipe when you don't do it yourself, but the output is printed just after the new prompt. (which is why i got confused)

        Thanks to all for the great feedback.
        It was really appreciated.