http://www.perlmonks.org?node_id=241472


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 t.pl line ##.
Can't use string ("") as a symbol ref while "strict refs" in use at t.pl 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.