Perl supports opening a pipe to or from a shell command, that's what the open call seems to try to accomplish. But for that, a pipe sign must be prepended (in case of writing to) or appended (in case of reading from) to the shell expression, like so:

open F, "| some_shell_expression"; # open for writing open F, "some_shell_expression |"; # open for reading

See open for details. Your open as written won't work, since you don't specify the open mode (read or write). The command itself as posted by you features a useless use of cat since it is better written as

/usr/bin/mycommand < file

The next line saves the input record separator (see perlvar), sets it to the empty string enabling "slurp mode" on the filehandle F; next all that can be read from F is read and then passed to eval to be executed. For that to work,

  1. something must be read from the filehandle F and
  2. the stuff read must be valid perl code.
See eval for details.

I suspect that there's nothing read from F, and evaling an empty string doesn't result in an error stored in $@.

If you just want to run a command and check it for errors, use system. If system returns something different than 0 (zero), something went wrong. Then exploit $? (see perlvar), along the lines

my $cmd = "/usr/bin/mycommand < file"; if ( system $cmd ) { warn $cmd . ($? == -1) ? " failed to execute: $!\n" : ($? & 127) ? sprintf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' : sprintf "child exited with value %d\n", $? >> 8; }

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Undestanding this code snippet by shmem
in thread Undestanding this code snippet by Anonymous Monk

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.