Whatever you are trying to do, that's not the way to do it! You seem to be trying to perform an end run around using symbolic references, but hiding that in a string eval doesn't actually "fix" the problem, and introduces all the nastiness of string eval on top of the nastiness of symbolic references.

Instead simply use %ENV wherever you would have used your "local" variables. The content of %ENV is "local" in any case - any changes you make to the content of %ENV only affects your executing script.

By attempting to copy environment variables to local variables you are introducing two types of nasty coding practise, you are obscuring where the values actually come from, and are making it harder to change the script in the future by requiring the introduction of "local" variables for each environment variable you may want to use. So don't do that.

The immediate problem with your code is that the right hand side of the assignment operator is whatever the contents of $ENV{$NB_VAR} is. If the contents are not numeric then the rhs of the assignment will be at best a bareword and often will simply be syntactically incorrect.

True laziness is hard work

In reply to Re: Why is my loop dropping alphabetic strings? by GrandFather
in thread Why is my loop dropping alphabetic strings? by DiabeticJim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.