biohisham has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...
So I have been toying with this concept these few days on my Ubuntu machine using Getopt::Long, what I basically aim to achieve is to pass parameters to the program such as the following:
$perl ReadingMultipleFiles.pl -param1 arg -param2 arg --file *.txt
So my program receives many other options that are strings or integers and I aim to run it on an entire folder of .txt files such that the user has an option of either calling the program on one file by passing the file name in this fashion$perl ReadingMultipleFiles.pl -param1 arg -param2 arg --file foo.txt
or just run it universally on all files via a glob (*) from the STDIN as mentioned above.Trying various tricks the closer I got to achieving this was through implementing options with multiple values or storing in a hash, however, in both cases, only one file from a group of files is read before the program exits.
I can't think of another way to do this and I don't want to drastically alter my program design so if I can get you to my rescuing esteemed ones it will be awesome.#strictures on #ReadingMultipleFiles.pl my @files; GetOptions( #many other integer and string options .... "file=s"=>\@files ..... ); foreach(@files){ print $_, "\n"; #only one file from a group } ### #a hash based way ### use Data::Dumper; my %hash; GetOptions(\%hash, 'files=s@'); print Dumper(\%hash); #only one file from a group
David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reading from a glob into Getopt::Long
by Corion (Patriarch) on Apr 03, 2012 at 09:34 UTC | |
by biohisham (Priest) on Apr 04, 2012 at 22:44 UTC | |
Re: Reading from a glob into Getopt::Long
by nicky (Novice) on Jul 30, 2015 at 18:08 UTC |
Back to
Seekers of Perl Wisdom