[Omaha.pm] Getopt::Long and opt_ variables

georgen@neillnet.com georgen at neillnet.com
Sun May 29 20:34:12 PDT 2005


<quote from="http://www.perl.com/doc/manual/html/lib/Getopt/Long.html">
Note that, if your code is running under the recommended use strict 'vars'
pragma, it may be helpful to declare these package variables via use vars
perhaps something like this:

  use vars qw/ $opt_size @opt_sizes $opt_bar /;
</quote>

so ... you just need to add,

use vars qw/ $opt_place /;

OR

remove the statement,

use strict;

HTH,
George.


> In the second edition camel (on page 448), it says that" "If no linkage is
> explicitly specified and no hash ref is passed, GetOptions() will put the
> value of in a global variable named after the option preceded by opt_..."
> Is this automagically done? This example doesn't seen to work .
>
> #!/usr/bin/perl -w
>
> use strict;
> use Getopt::Long;
> my $opt_place;
>
> &GetOptions("place=s");
>
> print "Hello! $opt_place\n";
>
> dthacker at fluffy:~/dev/dwofl/bin> ./test2.pl -place World Use of
> uninitialized
> value in concatenation (.) or string at ./test2.pl line 9. Hello!
>
> DT
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm at pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>




More information about the Omaha-pm mailing list