Warnings in Perl Eval -


i need hide warnings within eval rest of code should continue throw warning messages. here have -

eval "\$value = $hash->{key}"; 

now value of $hash->{key} function call, like:

$hash->{key} = "function(0.01*$another_var)"; 

the problem comes when $another_var undef (or ""). script craps out following message -

argument "" isn't numeric in multiplication (*) @ (eval 1381) line 1.

any suggestions how can avoid this? 1 option thinking parse value inside parenthesis , evaluate first, quite complex data dealing with.

wrap code in no warnings block.

... {     no warnings;     eval "\$value = $hash->{key}"; } ... 

you can disable specific classes of warnings. see perllexwarn hierarchy of warning categories , perldiag category particular warning belongs to.

{     no warnings qw(uninitialized numeric);     eval "\$value = $hash->{key}"; } 

(blah blah blah standard disclaimer 1 disable warnings unfit within 25 feet of adding machine blah blah)


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -