如何让 Eclipse/EPIC 停止发出有关“使用未初始化值 $ENV{whatever}”的警告?在我的 Perl 脚本中?
当 EPIC 第一次在 Perl 脚本中使用特殊的 %ENV 变量时,这会出现在 Eclipse 文本编辑器中。 我没有在这个环境中运行任何东西,我只是希望警告消失。
我在“运行配置”部分摆弄,但这似乎没有帮助。
更新1:所有这些答案都是关于更改代码,这应该是没有必要的。是的,如果我取消设置环境变量,我可能会在命令行上发生相同的错误。但我想在Eclipse中定义环境变量,以匹配正常的命令行环境,这样警告就不会发生。我尝试在 Eclipse 的“运行配置”中定义它,但它似乎没有生效。
我还尝试在 ~/.bashrc 和相关位置设置变量,并为 Eclipse 创建一个设置该变量的启动脚本。这些都没有解决警告问题。
我可以通过右键单击并选择“源”,然后选择“清除所有 EPIC 标记”来使警告消失,但下次更改文件时该警告会再次出现。
更新 2:如果我在运行配置中定义环境变量,然后运行脚本,它就可以顺利通过这些行。然而,当我编辑时,文本编辑器窗格中仍然显示一条波浪形的红色下划线和一条警告——这就是我想要删除的警告。
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 and 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当启用警告并且您尝试使用未定义的值时,这种情况也会发生在任何其他上下文中。
一些解决方案是
(1) 在使用变量之前定义它
(2) 使用
||
或//
运算符来替换变量的“默认”值(3 ) 禁用特定警告
(4) 禁用所有警告
(不要执行#4)。
由于这是 Perl,因此还有几种方法可以做到这一点。
在 Perl <= v5.8 中,您必须使用
||
和||=
而不是//
和// =
,它有一些细微不同的行为。This happens in any other context, too, when warnings are enabled and you try to use an undefined value.
Some solutions are
(1) to define the variable before you use it
(2) use
||
or//
operators to substitute a "default" value for your variable(3) disable the specific warnings
(4) disable all warnings
(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
不确定这是否有帮助,但尝试添加:
...在第一次使用 %ENV 之前。
[编辑:我假设相关的环境变量实际上已定义,并且此错误来自 IDE。再想一想,也许这是一个糟糕的假设。]
Not sure if this will help, but try adding:
...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.]