Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Parsing command line options without knowing what they are

by aquarium (Curate)
on Nov 25, 2010 at 01:32 UTC ( [id://873567]=note: print w/replies, xml ) Need Help??


in reply to Parsing command line options without knowing what they are

and also check the storing options in a hash documentation, as you don't need to pre-specify all options beforehand.
the hardest line to type correctly is: stty erase ^H
  • Comment on Re: Parsing command line options without knowing what they are

Replies are listed 'Best First'.
Re^2: Parsing command line options without knowing what they are
by DrWhy (Chaplain) on Nov 25, 2010 at 04:17 UTC
    This is the first thing I tried, but it doesn't do what I want. Yes, you can give it a hash reference and it will dump options in there, but you still have to name all the options that you want to support in the GetOptions() call. I have currently about 300 options that are supported, and this set will change over time. I don't want to have to keep going back to this code and changing the list here every time we add a new feature or remove an old one. What I need is something where I can give it a hash and it fills it up with whatever it finds on the command line without having to name each possible option.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      maybe Getopt::Regex?, and use a catch all regex with a sub to process each argument, e.g. store in hash or array.
      the hardest line to type correctly is: stty erase ^H
        I looked at this module last night and it's interesting, but it's too generic. I'd have to write too much of my own code to make this work, which is what I was hoping to avoid. I started poking around in Getopts::* on CPAN and did find a module that comes close to what I want, but not quite: Getopt::Casual.

        This module just parses a command line pulling out anything that looks like an option/switch/flag/whatever and uses some heuristics to decide if the following argument should be considered a value for that option/switch/... or not. Unfortunately one of those heuristics is exactly the opposite of what I want, so I think I'll give up and write my own code for this.

        --DrWhy

        "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://873567]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2025-03-26 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (67 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.