但是我用下面的代码测试了一下,却发现上面的第2、3句有问题:
#!/usr/bin/perl use strict; use warnings; use 5.010; my @a = ( 1, 2, 3 ); foreach my $t (@a) { print "$t\t"; } print "\n"; if ( @a ~~ /2/ ) { print "Match YES!\n";
} else { print "Match No\n"; } if ( @a ~~ 2 ) { print "Number YES!\n"; } else { print "Number No\n"; } if ( @a ~~ "2" ) { print "String YES!\n";
} else { print "String No\n"; }
输出结果: 1 2 3 Match YES! Number No String No
不知道谁能给解释一下?谢谢!
Jeova Sanctus Unus
unread,
Jan 17, 2011, 1:43:44 AM1/17/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sh...@googlegroups.com
~~操作符变了,5.010和5.012的不一样了 Any Array match against an array element 是说匹配的。不过书上说符合交换律,现在不符合了。 即@a ~~ 2和 2 ~~ @a不一样 你换下就知道了。不过我也不知道2 ~~ @a是啥意思,我再想想 你先2 ~~ @a写着吧 我记得这个问题我在这里问过。newsmth也有。 ps:感谢fvw以前的帮助XD
Jeova Sanctus Unus
unread,
Jan 17, 2011, 2:10:26 AM1/17/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message