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

I have some Perl code that formats a bit of text ($string) then creates a file (foo.bar) which is then called by an executable from within Perl. The executable then outputs a stream which is fed into a Perl variable $output.

What I would like to know is how to skip the step of creating a temp file. The executable expects a file, but I suspect STDIN may be sufficient?

Thanks in advance for any help!

$filename = "foo.bar"; open(TMP_SEQ, ">$filename"); print TMP_SEQ ">$string"; $output = `executable -f foo.bar`

Replies are listed 'Best First'.
Re: Calling Command That Expects a File Without Creating a File
by NetWallah (Canon) on Apr 05, 2012 at 04:55 UTC
    If you replace the content of "$filename" with CON: (for Windows), or /dev/stdout (for Linux), the output will go to STDOUT.

    That can then be redirected, or piped, at will.

                 All great truths begin as blasphemies.
                       ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

Re: Calling Command That Expects a File Without Creating a File
by mbethke (Hermit) on Apr 05, 2012 at 04:27 UTC
    Might be worth trying either nothing or a dash/minus as the file name, that's the unixish convention to tell a command that expects a file to use STDIN instead.
Re: Calling Command That Expects a File Without Creating a File
by Anonymous Monk on Apr 04, 2012 at 23:59 UTC

    The executable expects a file, but I suspect STDIN may be sufficient

    It may or may not, anyway, see IPC::Open3/IPC::Run3