after weeks of frustration of wanting to pass pipes as arguments to my programs, today i realized i can invoke my perl scripts like this by writing less (while having an excellent espresso):
join.pl "sort -t, A.csv |" "grep LALA B.csv | sort -t, |"
by removing "<" from open(). this still allows you to pass files too, keeping things "backwards-compatible"

this made me happy.

upon some further reflection, i think that this concept is more useful in OO code, for instance instead of implementing a method such as getFilename( ) you may want to use getFilehandleExpr( ) which is then passed to open($fh, $self->getFilehandleExpr( )). This gives you more flexibility later on when subclassing or implementing setFilehandleExpr( ) since the EXPR passed to open( ) is really a language of itself.

An example of using this technique would be implementing getFileHandleExpr( ) to write out to netcat or gpg or a file.

Replies are listed 'Best First'.
Re: passing pipes on the command line
by itub (Priest) on Mar 23, 2005 at 14:59 UTC
    Note that this use can be dangerous in situations where you are opening a file and the filename comes from an untrusted source (as is typically the case in CGIs, for example).

    If you are using bash as your shell, you can do effectively the same thing by using process substitution, even if the file is opened with "<":

    join.pl <(sort -t, A.csv |" "grep LALA B.csv | sort -t, )

    I suspect other shells (but probably not cmd.exe) may have similar features.

      That would probably be:
      join.pl <(sort -t, A.csv) <(grep LALA B.csv | sort -t,)
        Oops, you are right. I'm a victim of the cut-and-paste syndrome. :)
        hmm.. nice... so that just passes a FIFO as the filename...