in reply to Re^2: Why is my loop dropping alphabetic strings?
in thread Why is my loop dropping alphabetic strings?

The problem is Perl isn't assigning it to the variable. The if statements at the end are there to check and make sure the values were assigned to the variable. In the case of 'client01' it's failing while with a numeric value the variable is being defined. Is there better way of assigning the variable other than using the eval statement?

  • Comment on Re^3: Why is my loop dropping alphabetic strings?

Replies are listed 'Best First'.
Re^4: Why is my loop dropping alphabetic strings?
by aaron_baugher (Curate) on Jun 23, 2012 at 02:22 UTC

    Sorry, I wasn't clear: since you are using strict, that prevents Perl from treating the bareword as a string. Since you're doing it within an eval, your program doesn't die as it would if you did the same thing in non-eval code. It just fails to work. The post I replied to showed how to see any errors happening within the eval, so you can see why it's not working.

    The numeric assignment works because numbers don't ever have to be quoted like strings. Your eval sees two assignments, like these:

    $foo = 1; # no problem $bar = string; # bareword, fails under 'strict subs'

    And as Grandfather said, unless you're doing this as an exercise to learn how eval works, it's probably a really, really bad idea. Unless you have a very good reason that these values need to be in scalar variables instead of the %ENV hash (and there's nothing in your example to indicate that), just access the values from the hash where they belong. Anywhere that you're planning to use $FOO, there's no reason you can't use $ENV{FOO}.

    Aaron B.
    Available for small or large Perl jobs; see my home node.