@ARGV params with space?

K

Kev

Apologies if this is something simple but I can't find the answer
anywhere...Anyone able to point me in the right direction?

All I want to do is pass files to a perl script on the command line
(Windows) - simple enough usually. I'm having problems when the file I
want to pass has a space in the path...

i.e. perl script.pl c:\a dir with spaces\file.txt etc...

@ARGV[0] only contains as far as the first space.

What do I need to do pass the full path? I feel this should be really
simple but whatever it is I can't spot it.

Cheers and TIA,

Kev
 
J

Jürgen Exner

Kev said:
All I want to do is pass files to a perl script on the command line
(Windows) - simple enough usually. I'm having problems when the file
I want to pass has a space in the path...

i.e. perl script.pl c:\a dir with spaces\file.txt etc...

@ARGV[0] only contains as far as the first space.

What do I need to do pass the full path? I feel this should be really
simple but whatever it is I can't spot it.

It is indeed simple, although it has nothing to do with Perl.
You would do exactly the same as if you would want to pass the name to any
other program: just enclose the name in quotes.
That is how DOS and most other shells identify command line parameters that
span over several words.

jue
 
G

Greg Bacon

: All I want to do is pass files to a perl script on the command line
: (Windows) - simple enough usually. I'm having problems when the file I
: want to pass has a space in the path...
:
: i.e. perl script.pl c:\a dir with spaces\file.txt etc...
:
: @ARGV[0] only contains as far as the first space.
:
: What do I need to do pass the full path? I feel this should be really
: simple but whatever it is I can't spot it.

In general, it depends on your shell. You mentioned that you're
using Win32 (my sincerest sympathies), so use doublequotes:

C:\Temp>type try
#! perl

$" = "]["; # mjd's trick
print "\@ARGV = [@ARGV]";

C:\Temp>perl try foo bar baz "quux uushnu"
@ARGV = [foo][bar][baz][quux uushnu]

Hope this helps,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top