Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is probably a bizarre question, but I can't figure out how to get Getopt::Long to proccess something other than @ARGV. I've got a string (which I can easily make an array out of, if need be) that I would like to use for Getopt, but there is no mention of how to do this in the docs.

I would prefer a OO interface, but that isn't documented to well either, so if anyone knows the answer to the first question and knows about OO, please help me out with some code comments there.

I'd appreciate any help. Thanks!

Replies are listed 'Best First'.
(lestrrat) Re: Getopt::Long on Variable?
by lestrrat (Deacon) on Jan 16, 2002 at 03:30 UTC

    I usually just use this:

    { local @ARGV = @array; GetOptions( .... ); }
(Ovid) Re: Getopt::Long on Variable?
by Ovid (Cardinal) on Jan 16, 2002 at 03:38 UTC

    Add the data to @ARGV.

    #!/usr/bin/perl -w use strict; use Getopt::Long; my $size = 1; { local @ARGV = qw/ --size 20 /; GetOptions( 'size=s' => \$size ); } print 'x' x $size;

    That being said, exactly what are you trying to accomplish? Getopt::Long is designed to allow the person using the program to modify the program's behavior. If you wish to control the behavior from within the program, why don't you just assign to the variables directly? You could also use config files for different environments, if that is what you are looking for.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.