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

Since I am modifying the resultant hash drastically, it is very difficult to keep track of the changes in the hash.
  • Comment on Re^4: How to check if a scalar value is numeric or string?

Replies are listed 'Best First'.
Re^5: How to check if a scalar value is numeric or string?
by ikegami (Patriarch) on Aug 27, 2009 at 16:00 UTC

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