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

Hi, I'm current trying to squash a little bug I have regarding parameters and dashes. Currently I have something close to this in my script:
GetOptions { 'outdir=s' => \$out_dir, }
This works great, it sets my output directory and everything. Now comes the issue. Let's say a user uses a directory with a dash:
perl script.pl --outdir "D:\My-Folder"
Suddenly the parameter stops at the hyphen and the script pretty much ends there because "-Folder" is not a parameter and doesn't mesh with anything. This is using Strawberry Perl 5.18 on Windows 7. Any help would be greatly appreciated!

Replies are listed 'Best First'.
Re: Parameters and Dashes
by toolic (Bishop) on Sep 17, 2014 at 18:40 UTC
    Your code doesn't compile, but this works for me on both linux and windows (5.12):
    use warnings; use strict; use Getopt::Long; my $out_dir; GetOptions('outdir=s' => \$out_dir); print "$out_dir\n"; __END__ perl script.pl --outdir "D:\My-Folder" D:\My-Folder

    Perhaps there is some shell quoting problem.