Since I am modifying the resultant hash drastically,
Simply looking at the variable can change its internal format, so you don't want to rely on that.
$ perl -MDevel::Peek -le'$|=1; $x=1; Dump $x; print "x=$x"; Dump $x'
SV = IV(0x816a438) at 0x814f6cc
REFCNT = 1
FLAGS = (IOK,pIOK) <--- $x is a number
IV = 1
x=1
SV = PVIV(0x8150b10) at 0x814f6cc
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pPOK) <--- $x is a number and a string
IV = 1
PV = 0x81651b8 "1"\0
CUR = 1
LEN = 4
If you wanted to spend some effort, you could actually use the list you passed to GetOptions. If not, the following could do with very little effort:
sub reconstruct_toggle { ... }
sub reconstruct_with_val { ... }
sub reconstruct_opt_val { ... }
reconstruct(
foo => \&reconstruct_toggle,
bar => \&reconstruct_with_val,
special => sub { ... },
);
|