in reply to Re^2: How to check if a scalar value is numeric or string?
in thread How to check if a scalar value is numeric or string?

Why don't you save a copy of the command line before calling GetOptions?

If you can't because you're rearranging the command line somehow, you'll need to pass your reconstructor some of the information you pass to GetOptions (as in, whether a parameter is a toggle or takes a value).

Replies are listed 'Best First'.
Re^4: How to check if a scalar value is numeric or string?
by bgupta (Novice) on Aug 27, 2009 at 15:23 UTC
    Since I am modifying the resultant hash drastically, it is very difficult to keep track of the changes in the hash.

      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 { ... }, );