Newbie Question: Could someone show me how to implement options

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

  1. #1

    Default Newbie Question: Could someone show me how to implement options

    thanks,
    Borniac
    Borniac Guest

  2. Similar Questions and Discussions

    1. Implement data big question
      I need to build a map in which every time a customer rolls over a state a tooltip shows up. Now the thing is that the company building this map only...
    2. Urgent Paypal options question
      I just found out that when I have three option boxes, one of them doesn't show in the final Paypal shopping cart. The 3 options are: first, menu...
    3. Pen Tool Use Question. (Embarrassingly Newbie Question)
      I'm currently using Flash MX and whenever I choose the Pen Tool instead of the pen nib with the small "x" beside it that supposed to show up on...
    4. SHOW TABLES and related options for SQL are not working
      Hi, I have installed Perl from Active State.com in Win2K advanced server and no other Packages are installed. I am able to connect to Sql server...
    5. newbie - FMPro Web Companion - no show
      OK, I have followed intructions in the FMP Developer's and User's manuals. Simple scenario. I'm using the "Contact Management Solution" sample...
  3. #2

    Default Re: Newbie Question: Could someone show me how to implement options

    In article <150920032028070159%Borniac_1@hotmail.com>, Borniac wrote:
    > thanks,
    > Borniac
    Please don't put the question in the subject only...

    Untested:

    #!/usr/bin/perl -w

    use strict;
    use warnings;

    use Getopt::Std;

    my %opts;

    if (!getopts("hn:", \%opts) || (defined(%opts{h}) && $opts{h})) {
    die "Usage: $0 -h | -n name\n";
    }

    if (defined($opts{n})) {
    print "Hi $opts{n}!\n";
    }

    print "(Done)\n";


    Given -h: Will print usage info and die.
    Given -n name: Will print "Hi <name>!".

    See "perldoc Getopt::Std".

    --
    Andreas Kähäri
    Andreas Kahari Guest

  4. #3

    Default Re: Newbie Question: Could someone show me how to implement options

    Andreas Kahari <ak+usenet@freeshell.org> wrote in message news:<slrnbmc2tk.r0i.ak+usenet@vinland.freeshell.o rg>...
    > In article <150920032028070159%Borniac_1@hotmail.com>, Borniac wrote:
    >
    > if (!getopts("hn:", \%opts) || (defined(%opts{h}) && $opts{h})) {
    > die "Usage: $0 -h | -n name\n";
    > }

    You know, this brings up a question that's bugged me a while.

    Why should the idiom

    (defined($hash{key}) && $hash{key})

    be needed, really? Is it just to prevent a syntax error or undefined warning?

    If so, I'd like a

    no use blah_warnings;

    for it. Is there one?
    Bill Guest

  5. #4

    Default Re: Newbie Question: Could someone show me how to implement options

    [email]wherrera@lynxview.com[/email] (Bill) wrote:

    : You know, this brings up a question that's bugged me a while.
    :
    : Why should the idiom
    :
    : (defined($hash{key}) && $hash{key})
    :
    : be needed, really?

    The defined() part isn't needed. The only value of $hash{key} that
    would return false in that part will also return false in the second
    part.

    I wouldn't call that an idiom at all. The idiom would be to let
    $hash{key} in boolean context return false on undef.

    : Is it just to prevent a syntax error or undefined warning?

    No warning is produced if $hash{key} is undefind and the defined() test
    is eliminated.

    : If so, I'd like a
    :
    : no use blah_warnings;
    :
    : for it. Is there one?

    Yes, there is.

    no warnings 'undefined';

    Jay Tilton Guest

  6. #5

    Default Re: Newbie Question: Could someone show me how to implement options

    [email]tiltonj@erols.com[/email] (Jay Tilton) wrote:

    : [email]wherrera@lynxview.com[/email] (Bill) wrote:
    :
    : : If so, I'd like a
    : :
    : : no use blah_warnings;
    : :
    : : for it. Is there one?
    :
    : Yes, there is.
    :
    : no warnings 'undefined';

    Check that.

    no warnings 'uninitialized';

    Jay Tilton Guest

  7. #6

    Default Re: Newbie Question: Could someone show me how to implement options

    [This followup was posted to comp.lang.perl.misc]

    In article <150920032028070159%Borniac_1@hotmail.com>, Borniac_1
    @hotmail.com says...
    > thanks,
    > Borniac
    >
    #!/usr/bin/perl -w

    use Getopt::Std;

    %options = ( "d" => 0 , "c" => 0 , "s" => 0 , "S" => 0 ,
    "t" => 0 , "m" => 0 , "D" => 0 , "p" => 0 ,
    "f" => 0 );
    $status = getopts("DdftTspScmy:e:",\%options);
    if ( !$status ) {
    die("Usage : $0 [-dftTsScmp] [-e exclude_pattern]" .
    "[-y year] [pattern ... pattern]\n");
    } # IF
    Barry Kimelman Guest

  8. #7

    Default Re: Newbie Question: Could someone show me how to implement options

    Andreas Kahari wrote:
    >use Getopt::Std;
    My preferred way it to use Getopt::Long, like this:

    use Getopt::Long;
    GetOptions(\my %opt, 'id=i', 'verbose', 'foo=s');

    # see what we got:
    use Data::Dumper;
    print Dumper \%opt;

    use like:

    perl test.pl -verbose -id=123 -foo=abc FILES

    You may use single or double hyphens.

    --
    Bart.
    Bart Lateur Guest

  9. #8

    Default Re: Newbie Question: Could someone show me how to implement options

    In article <a73jmvs5btf518kdfb25tr3c2gcdu0saqd@4ax.com>, Bart Lateur
    <bart.lateur@pandora.be> wrote:
    > Andreas Kahari wrote:
    >
    > >use Getopt::Std;
    >
    > My preferred way it to use Getopt::Long, like this:
    >
    > use Getopt::Long;
    > GetOptions(\my %opt, 'id=i', 'verbose', 'foo=s');
    >
    > # see what we got:
    > use Data::Dumper;
    > print Dumper \%opt;
    >
    > use like:
    >
    > perl test.pl -verbose -id=123 -foo=abc FILES
    >
    > You may use single or double hyphens.
    Sorry It took so long
    I thank everybody for pointing me in the right direction
    I 'am using use Getopt::Long
    Borniac 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