rjschwei has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am trying to "clean up" some code using perlcritc and am running across the error that one should use the 3 argument version of open().

Generally this is pretty straight forward except in this case:

if (! open ($XML, "xsltproc $xslt $controlFile|")) { .... }
I know what is going on, xsltproc converts the file pointed to be $controlFile, this goes to stdout and the "|" at the end redirects, such that I end up with $XML being a file handle pointing to the converted file content.

Now the not so pretty version of this would be for me to call xlstproc and send the output to a temporary file and then use the temporary file in an open statement with 3 arguments. However, I am thinking there is a more compact way of doing this that appeases perlcritic and does not require me to write a temporary file to disk.


Help is appreciated.
Thanks,
Robert

Replies are listed 'Best First'.
Re: clean up to PBP for open
by BrowserUk (Patriarch) on Nov 05, 2011 at 12:42 UTC

    The third argument, the command, gets substituted for the place-holder '-' in the second argument:

    if (! open ($XML, '-|', "xsltproc $xslt $controlFile" )) { .... }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.