Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: GetOpt::Long usage style

by Aristotle (Chancellor)
on Mar 09, 2003 at 01:16 UTC ( #241472=note: print w/ replies, xml ) Need Help??

in reply to (jeffa) Re: GetOpt::Long usage style
in thread GetOpt::Long usage style

No eval, complies with strict:

our ($user,$pass,$numb,$help); my @cmdopt = ( [qw(user u=s)], [qw(pass p=s)], [qw(numb n=i)], [qw(help h ?)], ); GetOptions(map { +(join '|', @$_) => *{$main::{$_->[0]}}{SCALAR} } @cm +dopt);
It will even bomb out if your variable and option names mismatch:
Use of uninitialized value in ref-to-glob cast at line ##.
Can't use string ("") as a symbol ref while "strict refs" in use at line ##.
Of course, this assumes that the variables live in package main. If you need them elsewhere, the $main:: bit will need adjustment. It is possible to generalize even that bit, but that requires some painful twisting - or disabling the ref stricture.

Makeshifts last the longest.

Comment on Re^2: GetOpt::Long usage style
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-11-30 01:56 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (756 votes), past polls