As use is a compile-time statement, you will need to use eval to do this at run-time.
foreach (<THRESHOLDS>) { chomp($_); if (my ($name, $value) = $_ =~/^(\w+);(\d+);$/ && $_ !~/^\#/) { eval "use constant $name => $value;"; log_msg("Setting: use constant $name => $value;"); if ($Threslabels[$Threscount] ne $name) { log_msg("There is something wrong with the thresholds labels, check + threshold +s file!"); exit(2); } $Threscount++; } }
Also, note that I changed your use of $1 and $2 by assigning them to normal variables. This is a safety as well as documentation thing.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
In reply to Re: Define constant in loop
by dragonchild
in thread Define constant in loop
by penantes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |