Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: strict

by dimmesdale (Friar)
on Jul 24, 2002 at 22:07 UTC ( [id://185049] : note . print w/replies, xml ) Need Help??

in reply to Error when using strict pragma

you have to say my $opt_u, or the compiler will spit an error -- or you could say (assuming main package) $MAIN::opt_u and be gone with it.

This is because use strict requires you're variables to be declared -- or, as I think on it, you could say use vars qw/$opt_u ... others here.../; (hey, TMTOWTDI :)

May I suggest, however, that (I assume you're using a GetOpt:: module here) you don't let the GetOpt module assign $opt_<whatever>, but instead pass it a hash reference. This way you can say $opts->{<whatever>} and be done with it.

Replies are listed 'Best First'.
Re: Re: strict
by Bird (Pilgrim) on Jul 25, 2002 at 18:28 UTC
    I agree that you're probably better off just getting your opts out of the hash, but to clear up your initial comment, I'm pretty sure the (official/newest) way to declare it would be...

    our $opt_u;

    This makes it global and is necessary since you want to be accessing the same variable that Getopt is using.


    Update: Just read the comment by dws below. I was thinking of Getopt::Std. I have no idea how GetOpt works.