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

my $path = "C:/\"Program Files\"/\"Perl Express\"/example.txt;

This should be re-written. There is no need to "escape" double quotes - the whole path name should be in quotes, this \" doesn't make sense. Under Windows Perl, the following Perl $path name is completely valid:

#!/usr/bin/perl -w use strict; my $path = "C:/Program Files/Perl Express/example.txt"; #there is no need to "escape" the double quotes. print "$path\n"; my $root = "C:/Program Files/Perl Express"; my $somefile = "X Y Z.dat"; my $somefile_path = "$root/$somefile"; print "$somefile_path\n"; __END__ prints: C:/Program Files/Perl Express/example.txt C:/Program Files/Perl Express/X Y Z.dat

Replies are listed 'Best First'.
Re^2: How to escape white space in command line arguments
by GoForIt (Novice) on Apr 13, 2010 at 13:17 UTC
    Hi,

    Yes, you're right. For some reason, it wasn't working before so I chose to escape those white spaces which turned out to be totally unnecessary later.

    I really appreciate your response.

    Thanks,

    Off the topic, could someone please tell me if I need to close the thread in this forum? I read the FAQs and I couldn't find any related posts there. I just want to make sure that I follow the forum rules. Thanks!

        Off the topic, could someone please tell me if I need to close the thread in this forum?

      There is no need to. This is a good thread that will, in the future, help people who come by it.
        There is no closing of threads, ever :)
      GoForIt, I'm glad that you got some help from this thread and are able to proceed with your program! Hurray!

      This @ARGV business just means that this is a reserved array for Perl and normally you shouldn't assign to it or grow it by a push or whatever. I've never seen a 'C' or Perl program that did that, but of course "never" is a very long time!

      Perl normally "consumes" items from @ARGV via shift. The equivalent analog in 'C' is argv++. Getopts essentially works this way. Both of these operations make @ARGV smaller. There are also analogous operations that can consume the "rightmost" argument from the command line.

      JavaFan and I are probably in what I would call "aggressive agreement" - there isn't any real difference except that somehow the words via text seem to be in juxtaposition.

        Hooray! I found the coolest forum possible :)

        Thanks,