reading command line options from a file

R

Risto Vaarandi

hi all,
what is the best strategy for reading command line options from a file?
So far, I have used Getopt::Long for processing command line options,
but with some tools I've written command lines tend to get rather long.
I have been thinking of storing some options in a file - when a Perl
script starts, it reads the options from the file and pushes them to
@ARGV, and after that Getopt::Long::GetOptions() is called for the
modified @ARGV list. Is this the optimal way for solving the problem, or
are there better workarounds?
br,
risto
 
P

Paul Lalli

Risto said:
what is the best strategy for reading command line options from a file?
So far, I have used Getopt::Long for processing command line options,
but with some tools I've written command lines tend to get rather long.
I have been thinking of storing some options in a file - when a Perl
script starts, it reads the options from the file and pushes them to
@ARGV, and after that Getopt::Long::GetOptions() is called for the
modified @ARGV list. Is this the optimal way for solving the problem, or
are there better workarounds?

I *think* you're re-inventing a wheel. Does Getopt::ArgvFile do what
you want?
(http://search.cpan.org/~jstenzel/Getopt-ArgvFile-1.10/ArgvFile.pm)

Failing that, I don't see anything overly wrong with your idea, but
when you're populating @ARGV, make sure you use a module like
Text::parseWords
(http://search.cpan.org/~nwclark/perl-5.8.8/lib/Text/ParseWords.pm) to
split up the line from the file, rather than just splitting on
whitespace. That's so that a line like:
--name "Paul Lalli" --debug
will parse correctly into three arguments, not four.

It's also probably a good idea to localize @ARGV before populating it
from the file and letting Getopt::Long have at it.

Just my 2¢
Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top