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

Hello monks. I am trying to read the input from a multi-line command.

i.e. Given the following command:-

$./myscript.pl data_item1 data_item2 <<QQ<br> hello<br> world<br> QQ
I can read the two data_items physically specified on the command line by reading elements of @ARGV, but how does one read in those two additional lines of data ? I am trying to do this with perl 5.8.8

Replies are listed 'Best First'.
Re: use of << on comand line
by hippo (Archbishop) on Jun 04, 2018 at 14:18 UTC

    Try:

    my @shellheredoc = <STDIN>;

    PS. Don't forget to chomp if required.

      Or shift out the contents of @ARGV and use <>. This is a far more flexible and standard approach.

      Thanks. That worked. :)
Re: use of << on comand line
by Eily (Monsignor) on Jun 04, 2018 at 14:18 UTC

    That's the Heredoc syntax (as interpreted by your shell in thiscase, not perl). It simply writes the data to the standard input so you can read it with <STDIN> (the magical <> will try to use the parameters as the name of files to read from, unless you shift from @ARGV).

      Thanks Eily. It works now :) I'll have to remember to watch out for that magical <> feature you mentioned. I never realised it works like that... Fortunately I usually shift parameters from @ARGV.

        You can find the documentation for the feature in perlop (search for "The null filehandle"). And you'll find more info on the problems of the magical <> and a safer version here