in reply to Getopt::Std dies or returns empty var

Take a look at the documentation (Getopt::Std). The opt_x either need to be global or if you don't like globals, the second arg is a reference to a hash that will contain the options. The getopt function doesn't have a return value.

#!/usr/local/bin/perl -w use strict; use Getopt::Std; our( $opt_u ); getopt('u'); die "no u option passed\n" unless $opt_u; print "username is $opt_u\n";

-derby

Replies are listed 'Best First'.
Re: Re: Getopt::Std dies or returns empty var
by bonoboy (Sexton) on Mar 11, 2004 at 13:14 UTC

    Interesting. This works. I found some docs saying you had to use 'our' earlier, but the first time I tried running it 5.00503, it bitched about it being deprecated. Just ran it on 5.8 though and it worked. I'd assumed that if an earlier version barfed it, the newer one must be deprecated. This sucks too, cause the system I need it to run on can't really be upgraded :S

    toeslikefingers.com - because you've got too much time on your hands
      the system I need it to run on can't really be upgraded

      In that case, rather than declaring the variable with our $opt_u you should (must) declare a package variable with use vars qw/$opt_u/.

      Compatibility with older Perl interpreters is the main reason why I don't use our in my code.