Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello monks,

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.

#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
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.

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...

In reply to Reading from a glob into Getopt::Long by biohisham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (2)
    As of 2024-10-07 17:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The PerlMonks site front end has:





      Results (44 votes). Check out past polls.

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.