You can open an output file which is a pipe to 'program', then 'print' the output of your funciton to that pipe, as in:
open PROG, "|program" or die "Can't open output pipe to 'program'"; print PROG function(); close PROG;
It's concise, and comes pretty close to the the goal of the code itself describing what's going on.

Update: Oops! It's also not what you were asking for. (Sorry, I didn't read carefully, and didn't see the backticks in your code in my browser's font. )

IPC::Open2, as Tanktalus suggests is the most concise approach under Unix. I haven't had success with IPC::Open2 under MSWindows, either XP or 98 (Perl v5.8.6 and v5.8.4 respectively). On MSWindows I think you're stuck writing to a temporary file, as in :

my $input = "first line\nsecond line"; open TEMP, '>' "temp$$"; print TEMP $input; close TEMP; my $ouput = `type temp$$|\\vim\\vim63\\xxd.exe`; print $output; unlink "temp$$"; # (tested)
If you're sure you won't have newlines or other troublesome characers in the '$input' data, then what you started with, using 'echo', is about as good as you'll get. (Now watch, as a much cleverer monk proves me wrong.)

In reply to Re: piping a function into a backtick shell by rodion
in thread piping a function into a backtick shell by drawde83

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.