in reply to Re: Warning-free numerification of a string
in thread Warning-free numerification of a string

Thanks! Very sneaky, I like it. Probably a bit too sneaky to be considered maintainable, so I'll run with the latter. At least now I know I'm not missing a neat trick here.
  • Comment on Re^2: Warning-free numerification of a string

Replies are listed 'Best First'.
Re^3: Warning-free numerification of a string
by syphilis (Archbishop) on Aug 09, 2007 at 03:02 UTC
    If $_ is a string that that does not look_like_number(), then don't be fooled into thinking that $_ + 0 will inevitably evaluate to zero:
    $_ = '12*&&#$%'; $_ += 0; print $_, "\n"; # prints 12
    Cheers,
    Rob
Re^3: Warning-free numerification of a string
by varian (Chaplain) on Aug 08, 2007 at 22:09 UTC
    Not sneaky at all, just contain the no-warnings to where you need it and the requirement is crystal-clear:
    { no warnings 'numeric'; $val1 = $val1+0; # force numeric }