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

Guys, I have read some code that I don't quite understand, especially what the expression below on opening files.
open (SKEL, "cat " . join (" ", @ARGV) . " |") || die "Could not open +$ARGV[0].\n$usage";
I have trouble understanding what the it does, especially: "cat " . join (" ", @ARGV) . " |" Could you give me some hints? Thanks!

Replies are listed 'Best First'.
Re: First post, file handle question
by MidLifeXis (Monsignor) on Apr 17, 2013 at 17:21 UTC

    It is opening a pipe to read the output of the unix cat command followed by the parameters passed on the command line, joined by a space. So if you do myscript foo bar, it will read the output from the unix-like command cat foo bar and process it.

    Be aware that this is not the best way to do this. If I were to pass the following arguments /dev/null; echo rm -rf /; echo Gotcha! (but properly quoted and removing the first echo), your application would do much more than you wanted it to do. It would run the set of unix commands cat /dev/null; echo rm -rf /; echo Gotcha and give you the output from that (again, remove the echo from the rm command).

    --MidLifeXis

      So instead of putting all the command line argument files into a single file before going into this perl script, this lines execute the cat command inside a perl? I got that.
Re: First post, file handle question
by AnomalousMonk (Archbishop) on Apr 18, 2013 at 11:23 UTC
    open (SKEL, "cat " . join (" ", @ARGV) . " |") || die "Could not open $ARGV[0].\n$usage";

    Just a picky parenthetic note: If the special variable  $" retains its default value of a single space (see perlvar), the expression
        "cat " . join (" ", @ARGV) . " |"
    is exactly equivalent to the much shorter and clearer expression
        "cat @ARGV |"
    which, for some reason, the original author did not want (or know how) to use.