McDarren has asked for the wisdom of the Perl Monks concerning the following question:
Here is my scenario:
So far, so good (I think)... So I started playing around with Getopts:Std. I added code to my library like so:
use Getopt::Std; getopts('fs', \%opts);
I found that if I then referred to %opts from within the library, like so:
...it all works as expected. But if I try to refer to %opts from outside the library, I get:if ($opts{s}) { #do stuff }
Global symbol "%opts" requires explicit package name.....
The reason for the error is pretty obvious - the script doesn't know about %opts, and as I'm using strict, it barfs. But I'm not sure where to go from here. I'm guessing that I need to create a package, and refer to that - but I'm afraid that this is uncharted territory for me. I've tried putting this:
in the library, but that doesn't work.{ package FOO; use Getopt::Std; getopts('fs', \%opts); }
Can somebody point me in the right direction please?
Thanks,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sharing Getopts::Std amongst several related scripts
by ikegami (Patriarch) on Dec 13, 2005 at 15:35 UTC | |
by McDarren (Abbot) on Dec 13, 2005 at 16:15 UTC | |
by ikegami (Patriarch) on Dec 13, 2005 at 17:31 UTC |