in reply to How to escape white space in command line arguments

On Windows, you just double quote command line args that have spaces. @ARGV should be a read_only thing for a user. 2 simple Perl scripts and how they can interact:
#!/usr/bin/perl -w use strict; #file: testargv.pl my $parms = 'a b c abc "some gizmo" d32'; print `perl argv.pl $parms`; __END__ prints a b c abc some gizmo d32 ===== file argv.pl ======== #!/usr/bin/perl -w use strict; #file: argv.pl foreach (@ARGV) { print "$_\n"; } ==example of command line input to argv.pl ==== C:\TEMP>perl argv.pl "some thing" "some other thing" d x "xy z" some thing some other thing d x xy z

Replies are listed 'Best First'.
Re^2: How to escape white space in command line arguments
by JavaFan (Canon) on Apr 13, 2010 at 07:08 UTC
    @ARGV should be a read_only thing for a user.
    This raises several questions.
    1. What has the ability to write @ARGV to do with the problem?
    2. Why should it be read_only? Why isn't it read_only if it should?
    3. Who's the user in this case? The programmer? The person running the code?
      Well I just saw this from the OP:
      @ARGV = ("C:/Program Files/Perl Express/sample.txt", "some hash");

      @ARGV is a special Perl variable that contains the command line arguments. A similar thing exists in other languages. In 'C' you also get argc which is the count of the argv strings, e.g. int main(int argc, char **argv), but argc is redundant because argv is a null terminated array of pointers to strings and therefore calculating argc is trivial. Perl uses @ARGV for the purpose of passing command line args and the scalar value of @ARGV is what 'C' calls argc.

      Nobody but the O/S should set @ARGV.

        Nobody but the O/S should set @ARGV.
        Oh, really? So, shift is broken? Getopt::Long is very naughty, and doesn't get Christmas presents?

        And the OS doesn't even populate @ARGV. It's perl that does that - and it's not always a full copy of argv.

        Besides, this is Perl. Perl will do whatever I want.