开发者

How do I get Eclipse/EPIC to stop warning about "Use of uninitialized value $ENV{whatever}" in my perl script?

开发者 https://www.devze.com 2023-03-10 10:28 出处:网络
This appears in the Eclipse text editor the first time EPIC encounters use of the special %ENV variable in a Perl script.

This appears in the Eclipse text editor the first time EPIC encounters use of the special %ENV variable in a Perl script. I'm not running anything in this environment, I just want the warning to go away.

I fiddled around in the "run configurations" section, but that didn't seem to help.

UPDATE 1: All these answers are about changing the code, which should not be necessary. Yes, I can get the same error to happen on the command line if I un-set the environment variable. But I want to define the environment variable in Eclipse, to match the normal command line environment, so that the warning does not happen. I've tried defining it in the Eclipse 'Run configuration', but it doesn't seem to take effect.

I also tried setting the variable in ~/.bashrc 开发者_如何学Goand related places, and creating a startup script for Eclipse that sets the variable. None of that fixed the warning.

I can make the warning disappear by right-clicking and selecting 'Source' and then 'Clear All EPIC Markers', but the warning appears again the next time the file is changed.

UPDATE 2: If I define the environment variables in the Run Configuration, and then run the script, it gets past those lines okay. However, there is still a squiggly red underline and a warning displayed in the text editor pane while I'm editing -- it's that warning I want to get rid of.


This happens in any other context, too, when warnings are enabled and you try to use an undefined value.

$ perl -we 'print $ENV{NOT_DEFINED}'
Use of uninitialized value in print at -e line 1.

Some solutions are

(1) to define the variable before you use it

$ perl -we '$ENV{NOT_DEFINED} //= ""; print $ENV{NOT_DEFINED}'

(2) use || or // operators to substitute a "default" value for your variable

$ perl -we 'print $ENV{NOT_DEFINED} // ""'

(3) disable the specific warnings

$ perl -we 'no warnings "uninitialized"; print $ENV{NOT_DEFINED}'

(4) disable all warnings

$ perl -we 'no warnings; print $ENV{NOT_DEFINED}'

(don't do #4).

Since this is Perl, there are several more ways to do it.

In Perl <= v5.8, you have to use || and ||= instead of // and //=, which has some subtly different behavior.


Define the environment variable before startup or fix the code so that it doesn't emit the warning. You might get more useful suggestions if you included the entire warning so that the reader would know where the it's coming from.


Actually I believe this is not currently possible, see this feature request and forum post


Not sure if this will help, but try adding:

our %ENV

...before the first use of %ENV.

[Edit: I am assuming that the relevant environment variable actually is defined, and this error is coming from the IDE. On second thought, perhaps this is a poor assumption.]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号