perl - CGI Perl 在字符串中使用未初始化的值 $user
问题描述
我在检查我用 CGI 检索的变量是否正确时遇到问题。
HTML:
<label for="name">Nombre de Usuario:</label>
<input type="text" id="name" name="user_name" />
<label for="password">Contraseña:</label>
<input type="password" id="password" name="user_password" />
CGI/Perl 代码:
my $c = CGI->new;
.
.
.
my $user = $c->param('user_name');
my $password = $c->param('user_password');
if($user eq "" || $password eq "") {
printf "Error";
exit;
}
主要问题是,如果我这样做:
print $user;
输出是正确的,它打印了值,但是在 apache error.log 中,它仍然说变量未初始化,然后进入“if”并退出。
我还尝试使用“$user”并将字符串与 undef 进行比较,但没有。
解决方案
要测试变量是否具有定义的值,您应该使用“定义”函数:
if (!defined($user) || !defined($password)) { ... }
推荐阅读
- r - 当数据框在列表中时,为什么我不能更改某些列的类型?
- laravel - 为 Laravel 中的每个页面添加脚本
- r - R - 在我的数据框中创建一个列,其中包含每个列表的名称(在列表对象的列表中)基于彼此之间的重叠
- java - 两个应用程序之间传输数据的方式?
- javascript - Promise 的问题
- firebase - 队列在飞镖/颤振中
- f# - F#中for循环中的'->'和'do'有什么区别
- javascript - 内联 CSS 与 Webpack,没有 HtmlWebpackInlineSourcePlugin?
- javascript - 如何在js中关闭“复选框”下拉菜单?
- tensorflow2.0 - 如何在 TensorFlow 2.n 中启用设备放置日志记录 (log_device_placement)