Perl Smart Match不接受字符串比较

时间:2017-04-04 17:35:40

标签: perl

将我的脚趾浸入perl。我有一个基于菜单的系统,其输入由给定/ when语句处理。虽然我的大部分输入都是数字,但我希望能够将“帮助”数字作为输入,然后为特定数字吐出帮助。我正在尝试使用正则表达式来隔离帮助部分来处理命令,但智能匹配期望使用数字而不是字符串。

在另一个功能中,我有:

 my $MenuInput = <STDIN>;
 chomp $MenuInput;
 MenuProcess($MenuInput);

然后处理该输入的子程序:

sub MenuProcess {
          my $value = @_[0];     
          given ($value){
                  when(1)         {CStatus()}
                  when(2)         {CInstall()}
                  when(3)         {CUpg()}
                  when(4)         {CDest()}
                  when(5)         {exit 0}
                  when($value =~ /help/)
                  {
                          print "help";
                  }

          }
 }

最终,“打印”帮助“将被处理用户需要帮助的任何特定菜单选项取代。

我收到此错误

Argument "help " isn't numeric in smart match at ./manage.pl line 59, <STDIN> line 1.

我指定了use 5.016;,我的perl -v输出如下:

$ perl -v

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 34 registered patches, see perl -V for more detail)

Copyright 1987-2012, 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.

0 个答案:

没有答案