Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Getopts::std

    I am using various switches in my script. I have the Getopts::std
    module and I wrote the following line:
    getopts('F:S:D:T:I:plen', \%OPTS);

    How can I see if the switch, such as -F, was followed by an argument?
    What I mean is that if in the prompt I write:
    ./example.pl -F
    How can I stop the script and check if -F was actually followed by an
    argument and what that argument is?

    lnatz Guest

  2. Similar Questions and Discussions

    1. Problem using Getopts package
      I am getting errors when I try to get command line parameters. For example this small code doesn't work on my machine....
    2. GetOpts: boolean and argument value combos
      Hey Perl Peps, I am stuck in the mudd and hoping someone can give me a few clues that will help get me back on track. I want to submit some...
  3. #2

    Default Re: Getopts::std

    lnatz wrote:
    > I am using various switches in my script. I have the Getopts::std
    > module
    This is the second time you've posted a message about a non-existing
    module. I can only *assume* you meant the module Getopt::Std, and its
    getopts() function. Spelling and capitalization both count. Please put
    some care into your posts.
    > and I wrote the following line:
    > getopts('F:S:D:T:I:plen', \%OPTS);
    >
    > How can I see if the switch, such as -F, was followed by an argument?
    > What I mean is that if in the prompt I write:
    > ./example.pl -F
    > How can I stop the script and check if -F was actually followed by an
    > argument and what that argument is?
    This is such an absurdly easy thing to check, I have to ask why you
    didn't. I've never used this module in my life, but it took me all of
    5 minutes to find it on CPAN (including account for your misspellings),
    read the documenation enough to see this:

    "For those of you who don't like additional global variables being
    created, getopt() and getopts() will also accept a hash reference as an
    optional second argument. Hash keys will be x (where x is the switch
    name) with key values the value of the argument or 1 if no argument is
    specified."

    and then run a small test case to verify:

    $ perl -MData::Dumper -MGetopt::Std -e'getopts(q{oif:}, \%opts); pri
    nt Dumper \%opts' -- -o -f
    $VAR1 = {
    'f' => undef,
    'o' => 1
    };

    It seems that options which take a value but are not provided a value
    get the undefined value. Why didn't you put this much effort into your
    own post?

    Paul Lalli

    Paul Lalli Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139