Ask a Question related to PERL Miscellaneous, Design and Development.
-
Borniac #1
Newbie Question: Could someone show me how to implement options
thanks,
Borniac
Borniac Guest
-
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... -
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... -
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... -
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... -
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... -
Andreas Kahari #2
Re: Newbie Question: Could someone show me how to implement options
In article <150920032028070159%Borniac_1@hotmail.com>, Borniac wrote:
Please don't put the question in the subject only...> thanks,
> Borniac
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
-
Bill #3
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
-
Jay Tilton #4
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
-
Jay Tilton #5
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
-
Barry Kimelman #6
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...#!/usr/bin/perl -w> thanks,
> Borniac
>
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
-
Bart Lateur #7
Re: Newbie Question: Could someone show me how to implement options
Andreas Kahari wrote:
My preferred way it to use Getopt::Long, like this:>use Getopt::Std;
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
-
Borniac #8
Re: Newbie Question: Could someone show me how to implement options
In article <a73jmvs5btf518kdfb25tr3c2gcdu0saqd@4ax.com>, Bart Lateur
<bart.lateur@pandora.be> wrote:
Sorry It took so long> 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.
I thank everybody for pointing me in the right direction
I 'am using use Getopt::Long
Borniac Guest



Reply With Quote

