+ -
当前位置:首页 → 问答吧 → Perl 智能操作符 比较 数组 和 标量 无法成功 (问题)

Perl 智能操作符 比较 数组 和 标量 无法成功 (问题)

时间:2010-10-20

来源:互联网

如题:
下载 (9.43 KB)
2010-10-20 09:37


请问是什么问题!

作者: panxinming90   发布时间: 2010-10-20

回复 panxinming90


    奇怪啊,我按照你的代码测了一下,能显示Yes啊。要不把你的代码贴上来,一起看看

作者: 珞水的大叔   发布时间: 2010-10-20

代码如下:
  1. #!/usr/local/bin/perl -w

  2. use strict;
  3. use 5.010;

  4.         my $str = "10";

  5.         my @strs = qw/ 9 10 11 /;
  6.         say "Yes" if @strs ~~ $str;
复制代码
[root@54 scripts]# /usr/local/bin/perl -v

This is perl 5, version 12, subversion 1 (v5.12.1) built for i686-linux

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

[root@54 scripts]#

作者: panxinming90   发布时间: 2010-10-20

5.12要写
$str ~~ @strs

而不能写
@strs ~~ $str

作者: 黑色阳光_cu   发布时间: 2010-10-20

回复 黑色阳光_cu


    测试 OK, thank you !

作者: panxinming90   发布时间: 2010-10-20