分隔符编码的问题
如果我按原样运行此脚本,它就会起作用。
但为什么这不适用于 cgi
?
当我使用 _\01_
而不是 _\00_
时,它也适用于 cgi
。
#!/usr/bin/env perl
use warnings;
use 5.012;
### script_1.cgi #########################################
my @array = ( '1524', '2.18 MB', '09/23/03', '_cool_name_', 'type' );
my $row = join "_\00_", @array;
say $row;
# submit $row to script_2.cgi
### script_2.cgi #########################################
# ...
# my $row = $cgi->param('row');
# my $name;
if ( $row =~ /_\00_([^\00]+)_\00_type\z/ ) {
# $name = $1;
say "Name: <$1>";
} else {
die "<$row> $!";
}
# Software error:
# <1524_�_2.18 MB_�_09/23/03_�__cool_name__�_type> at script_2.cgi line of "die "<$row> $!";"
If I run this script as it is, it works.
But why does this not work with cgi
?
When I use _\01_
instead of _\00_
it works with cgi
too.
#!/usr/bin/env perl
use warnings;
use 5.012;
### script_1.cgi #########################################
my @array = ( '1524', '2.18 MB', '09/23/03', '_cool_name_', 'type' );
my $row = join "_\00_", @array;
say $row;
# submit $row to script_2.cgi
### script_2.cgi #########################################
# ...
# my $row = $cgi->param('row');
# my $name;
if ( $row =~ /_\00_([^\00]+)_\00_type\z/ ) {
# $name = $1;
say "Name: <$1>";
} else {
die "<$row> $!";
}
# Software error:
# <1524_�_2.18 MB_�_09/23/03_�__cool_name__�_type> at script_2.cgi line of "die "<$row> $!";"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_cool_name_
说,对我有用。您可能与 CGI.pm 已经使用\0
发生冲突,但由于您没有发布完整的代码,所以没有人可以肯定。我将利用这个机会来回答这个问题。您应该吸取的教训是:
Works for me, says
_cool_name_
. You're probably running afoul of CGI.pm using\0
already for itself, but since you did not post your complete code, no one can say for sure.I'll use the opportunity to unask the question. The lessons you should learn are: