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

I want to use my script where it sucks in everything in a command line option like:
%my_perl_script.pl foo1 foo2 foo3
Where it would be the same thing as if internal to the script I had hardcoded it as:
$my args = q{foo1 foo2 foo3};
I've tried the below options and using the Getopt::Long, but can't get it right. What am I missing?
my $args = q{@ARGV};
my $args = @ARGV;

Replies are listed 'Best First'.
Re: Take in command line arguments as an entire string?
by LanX (Saint) on Aug 22, 2018 at 04:48 UTC
    You want the variables to be interpolated.

    Try  my $args = qq{@ARGV};

    You could also use plain double quotes instead.

    Or join " ", @ARGV

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice out

      Thanks! Those worked.
Re: Take in command line arguments as an entire string?
by kcott (Archbishop) on Aug 22, 2018 at 05:54 UTC

    G'day proxie,

    See the special variable $" (aka $LIST_SEPARATOR). Some examples:

    $ perl -le 'print @ARGV' foo1 foo2 foo3 foo1foo2foo3 $ perl -le 'print "@ARGV"' foo1 foo2 foo3 foo1 foo2 foo3 $ perl -le 'local $" = "~"; print @ARGV' foo1 foo2 foo3 foo1foo2foo3 $ perl -le 'local $" = "~"; print "@ARGV"' foo1 foo2 foo3 foo1~foo2~foo3

    If you want to change the value of $", or indeed any special variable, you'd be well advised to use local. It might be considered overkill in little one-liner such as I have there, but it's a good habit to get into. In an actual script, I'd recommend doing it always.

    — Ken

      Hi Ken,

      You might want to add the $OUTPUT_FIELD_SEPARATOR aka $,

      :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        G'day LanX,

        ++ That's a good point. Thanks.

        And sorry for the late reply. I've had some serious dental issues of late: mostly been drugged up to the eyeballs on strong pain killers.

        — Ken

Re: Take in command line arguments as an entire string?
by TheloniusMonk (Sexton) on Aug 22, 2018 at 08:43 UTC
    Although if you later want more capability on the command line, you might want to look at Getopt::Long and Getopt::Std