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

On the second trip through the loop, eval is passed this interpolated string:

$NB_ORA_CLIENT = client01

That's the bareword that strict is complaining about. When Perl sees a bareword, it looks to see if it's a subroutine name (which is why "strict subs" applies to it) and tries a few other possibilities (like is it being used as a hash key). If it can't figure out what it's supposed to be, it falls back to treating it as a string (like a shell does). So the string "client01" gets assigned to the variable by eval, but Perl isn't happy about it.

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

Replies are listed 'Best First'.
Re^3: Why is my loop dropping alphabetic strings?
by DiabeticJim (Initiate) on Jun 23, 2012 at 01:42 UTC

    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?

      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.