Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getopts problem

0 views
Skip to first unread message

BS

unread,
Apr 27, 2006, 10:42:56 PM4/27/06
to
Hi,

I just installed perl 5.8.8 on a xp pro box and having issues with the
getopts. If execute the script directly on the command line, the flags
in the script do not get set. If I run the script by prefixing the
per.exe, getopts works correctly. Any pointers how can I resolve this?
The script is pasted below. It dies on the very first die statement.

#!c:/per/bin/perl
use Getopt::Std;
getopts('a:c:');

die "Getopt not working opt a not set\n" if ( ! defined($opt_a) );
die "Getopt not working opt c not set\n" if ( ! defined($opt_c) );
print "$opt_a is the value for opt a\n";
print "$opt_c is the value for opt c\n";

BS

unread,
Apr 28, 2006, 8:59:50 AM4/28/06
to
Update with the screenshot

C:\>type a.pl
#!c:\perl\bin\perl

use Getopt::Std;

getopts('a:s:');

die "Error with getopt\n" if ( ! defined($opt_a) );
print "$opt_a\n" if ( defined ( $opt_a ) );
print "$opt_s\n" if ( defined ( $opt_s ) );

C:\>perl a.pl -atest -stest
test
test

C:\>a.pl -atest -stest
Error with getopt

Paul Lalli

unread,
Apr 28, 2006, 9:24:39 AM4/28/06
to

I'm guessing this is the same problem as was posted here a couple times
since January. It is not a matter of Getopt::Std having a problem, but
rather the command line arguments themselves not being passed to your
perl script.

If I'm right, you need to fix your file associations in Windows.
Please see the following thread to see if the solution there fixes your
issue:
http://groups.google.com/group/perl.beginners/browse_frm/thread/694dc8137f0264f8/7e6502ee06e5a7c5?q=windows+command+line&rnum=18#7e6502ee06e5a7c5

Paul Lalli

BS

unread,
Apr 28, 2006, 9:46:07 AM4/28/06
to
awesome :-). The association was already there but hosed up. I had to
restore it using the restore button insted of advance. Thanks for your
help Paul.

0 new messages