|
Posted by Paul Lalli on October 20, 2006, 3:59 pm
Please log in for more thread options
Hemant Shah wrote:
> Here is the sample perl script:
>
>
> #!/usr/bin/perl
>
> use Getopt::Std;
>
> my %Options;
>
> getopts('C:', \%Options);
>
> print "Comment = $Options\n";
> print "ARGV[0] = $ARGV[0]\n" if ($ARGV[0]);
>
> When I run the script as follows:
>
> ./tstgetopts.pl -a"Comment"
> Unknown option: a
> Comment = omment
>
> Why does getopts set value for $Options?
> It should be a left in %ARGV.
>
> If I use space in between then it works as expected.
>
> ./tstgetopts.pl -a "Comment"
> Unknown option: a
> Comment =
> ARGV[0] = Comment
>
> Is this a bug or am I missing something?
You're missing something.
Quotes are not a shell argument separator. This has nothing to do with
Perl, btw. Saying
./tstgetopts.pl -a"Comment"
is exactly the same as
./tstgetopts.pl -aComment
Getopts assumes that one switch is a cluster of single switches, until
it gets to C, which takes a value....
Take a look at this example, and see if that helps you understand:
perl -le'print for @ARGV' foo bar foo "bar" foo"bar"
foo
bar
foo
bar
foobar
Hope this helps,
Paul Lalli
|