免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6991 | 回复: 10
打印 上一主题 下一主题

新手遇perl难题,请求指导。急! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-20 16:04 |只看该作者 |倒序浏览
下面是我编的一个小程序,在调试时出了点问题:
unrecognized character \xc4 at C:\doucume~1\ADMINI~1\LOCALS~1\TEMP\DIR6C.TMP\bei_danci.pl line 57.
#!/usr/bin/perl

use strict;

print(
       "ÄãºÃ£¬ÕâÊÇÒ»¸ö±³ËÐÈí¼þ¡£\n",
       "ʹÓÃʱÐëÏȵ¼Èëµ¥´ÊÔÙ±³ËС£\n",
       "ÏÖÔÚÇëÑ¡Ôñ£º\n",
       "1---------µ¼Èë\n",
       "2---------±³ËÐ\n"
      );
chomp(my $choice_1 = <STDIN>);
print "&Ccedil;&euml;&cedil;&oslash;&Auml;&atilde;&micro;&Auml;&micro;&yen;&acute;&Ecirc;&frac14;&Ccedil;&Acirc;&frac14;&Icirc;&Auml;&frac14;&thorn;&AElig;&eth;&Atilde;&ucirc;&iexcl;&pound;\n";
chomp(my $my_dbm = <STDIN>);
if ($choice_1 < 1 || $choice_1 > 2){
       print "&Ccedil;&euml;×&ETH;&Iuml;&cedil;&iquest;&acute;&Euml;&micro;&Atilde;÷&iexcl;&pound;\n";
}elsif($choice_1 = 1){
       dbmopen(my %words,"$my_dbm",0644)
          or die "&Icirc;&THORN;·¨&acute;ò&iquest;&ordf;&raquo;ò&acute;&acute;&frac12;¨&Icirc;&Auml;&frac14;&thorn;&pound;&ordm;$!";
       print "&Ccedil;&euml;&Ecirc;&auml;&Egrave;&euml;&micro;&yen;&acute;&Ecirc;&iexcl;&pound;\n";
       chomp(my $word = <STDIN>);
       print "&Ccedil;&euml;&Ecirc;&auml;&Egrave;&euml;&Ograve;&acirc;&Euml;&frac14;&iexcl;&pound;\n";
       chomp(my $meanning = <STDIN>);
       if ($words{$word} != ""){
             print ("$word &Ograve;&Ntilde;&frac34;&shy;&Oacute;&ETH;&Ograve;&raquo;&cedil;&ouml;&Ograve;&acirc;&Euml;&frac14;&Ecirc;&Ccedil;&pound;&ordm;$words{$word},\n",
                    "&Iuml;&Ouml;&Ocirc;&Uacute;&Ccedil;&euml;&Ntilde;&iexcl;&Ocirc;&ntilde;&pound;&ordm;\n",
                    "1---------&Igrave;í&frac14;&Oacute;\n",
                    "2---------&ETH;&THORN;&cedil;&Auml;\n"
             );
       chomp(my $choice_2 = <STDIN>);
             if ($choice_2 < 1 || $choice_2 > 2){
                    print "&Ccedil;&euml;×&ETH;&Iuml;&cedil;&iquest;&acute;&Euml;&micro;&Atilde;÷&iexcl;&pound;\n";
             }elsif($choice_2 = 1){
                    $words{$word} .= $meanning;
             }else{
                    $words{$word} = $meanning;
             }
       print ("&Auml;&atilde;&Otilde;&aelig;&acute;&Iuml;&Atilde;÷&pound;&not;$word&micro;&Auml;&Ograve;&acirc;&Euml;&frac14;&frac34;&Iacute;&Ecirc;&Ccedil;$meanning&iexcl;&pound;\n",
              "&Ccedil;&euml;&Ntilde;&iexcl;&Ocirc;&ntilde;&pound;&ordm;\n",
              "1---------&frac14;&Igrave;&ETH;&oslash;\n",
              "2---------&Iacute;&Euml;&sup3;&ouml;\n"
              );
       chomp(my $choice_3 = <STDIN>);
       if ($choice_2 < 1 || $choice_2 > 2){
              print "&Ccedil;&euml;×&ETH;&Iuml;&cedil;&iquest;&acute;&Euml;&micro;&Atilde;÷&iexcl;&pound;\n";
       }elsif($choice_3 = 1){
              next;
       }else{
              last;
       }
}else{
        dbmopen(my %words,"$my_dbm",0644)
          or die "&Icirc;&THORN;·¨&acute;ò&iquest;&ordf;&raquo;ò&acute;&acute;&frac12;¨&Icirc;&Auml;&frac14;&thorn;&pound;&ordm;$^E";
       if (my ($word , $meanning) = each(%words)){
               print "&Ccedil;&euml;&Icirc;&Ecirc; $word &micro;&Auml;&Ograve;&acirc;&Euml;&frac14;&Ecirc;&Ccedil;&Ecirc;&sup2;&Atilde;&acute;?\n;
               if ($meanning eq chomp(<STDIN>)){
                     print "&Auml;&atilde;&Otilde;&aelig;&acute;&Iuml;&Atilde;÷$word&micro;&Auml;&Ograve;&acirc;&Euml;&frac14;&frac34;&Iacute;&Ecirc;&Ccedil;$meanning.\n",                           "&Ccedil;&euml;&Ntilde;&iexcl;&Ocirc;&ntilde;:\n",
                           "1.&frac14;&Igrave;&ETH;&oslash;\n",
                           "2.&Iacute;&Euml;&sup3;&ouml;\n";

               }else{
                            print ("&ordm;&Uuml;&Ograve;&Aring;&ordm;&para;&pound;&not;&Auml;&atilde;&acute;&eth;&acute;í&Aacute;&Euml;&iexcl;&pound;\n",
                                  "$word&micro;&Auml;&Ograve;&acirc;&Euml;&frac14;&Ecirc;&Ccedil;--$meanning.\n"
                                  );
                     chomp(my $choice_3 = <STDIN>);
                     if ($choice_2 < 1 || $choice_2 > 2){
                             print "&Ccedil;&euml;×&ETH;&Iuml;&cedil;&iquest;&acute;&Euml;&micro;&Atilde;÷&iexcl;&pound;\n";
                     }elsif($choice_3 = 1){
                             next;
                     }else{
                             last;
                     }
        }else{
               print "&Ograve;&Ntilde;&frac34;&shy;&Atilde;&raquo;&Oacute;&ETH;&micro;&yen;&acute;&Ecirc;&Aacute;&Euml;&pound;&not;&Ccedil;&euml;&Igrave;í&frac14;&Oacute;&iexcl;&pound;\n";
               last;
        }
57行我已经用红色标出,
可那一行没有\xc4代表的“-”啊?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2006-09-20 17:19 |只看该作者
看起来是那个文字的问题..注意看看他们的编码中可能有和 " 相同的出现...
或 "\"...

论坛徽章:
0
3 [报告]
发表于 2006-09-21 10:20 |只看该作者
字符的问题 把那些字符都变成英文就应该好了

论坛徽章:
0
4 [报告]
发表于 2006-09-21 13:27 |只看该作者
十分感谢。
可是现在又出问题了:
#!/usr/bin/perl

use strict;

BEGIN: print(
       "你好,这是一个背诵软件。\n",
       "使用时须先导入单词再背诵。\n",
       "现在请选择:\n",
       "1---------导入\n",
       "2---------背诵\n",
       "3---------退出\n"
            );
chomp(my $choice_1 = <STDIN>);
print "请给你的单词记录文件起名。\n";
chomp(my $my_dbm = <STDIN>);
if ($choice_1 < 1 || $choice_1 > 3){
       print "请仔细看说明。\n";
}elsif($choice_1 = 1){
       dbmopen(my %words,"$my_dbm",0644)
         or die "无法打开或创建文件:$^E";
DAO_R: print "请输入单词。\n";
       chomp(my $word = <STDIN>);
       print "请输入意思。\n";
       chomp(my $meanning = <STDIN>);
       if ($words{$word} != ""){
             print ("$word 已经有一个意思是:$words{$word},\n",
                    "现在请选择:\n",
                    "1---------添加\n",
                    "2---------修改\n"
             );
       chomp(my $choice_2 = <STDIN>);
             if ($choice_2 < 1 || $choice_2 > 2){
                    print "请仔细看说明。\n";
             }elsif($choice_2 = 1){
                    $words{$word} .= $meanning;
             }else{
                    $words{$word} = $meanning;
             }
       print ("请选择:\n",
              "1---------继续\n",
              "2---------退出\n"
              );
       chomp(my $choice_3 = <STDIN>);
       if ($choice_3 < 1 || $choice_3 > 2){
              print "请仔细看说明。\n";
       }elsif($choice_3 = 1){
              goto DAO_R;
       }else{
              goto BEGIN;
       }
}elsif($choice_1 = 2){
        dbmopen(my %words,"$my_dbm",0644)
          or die "无法打开或创建文件:$^E";
BEI_S:  if (my ($word , $meanning) = each(%words)){
               print "请问 $word 的意思是什么?\n";
               if ("$meanning.\n" eq (<STDIN>)){
                     print ("$word  就是 $meanning. \n",
                            "请选择: \n",
                            "1---------继续\n",
                            "2---------退出\n"
                           );
                     chomp(my $choice_4 = <STDIN>);
                     if ($choice_4 < 1 || $choice_4 > 2){
                             print "请仔细看说明。\n";
                     }elsif($choice_4 = 1){
                             goto BEI_S;
                     }else{
                             goto BEGIN;
                     }
               }else{
                            print ("很遗憾,你答错了。\n",
                                  "$word的意思是--$meanning.\n"
                                  );
               }

        }else{
               print "已经没有单词了,请添加\退出。\n";
               goto BEGIN;
        }
}else{
        print "welcome.\n";
}调试器说:
missing right curly or square bracket at line 82.
syntax error at line 82.
就是下划线部分部分。
请问是什么问题?
怎么改?
再次谢谢.

[ 本帖最后由 kid@B_Sky 于 2006-9-21 13:30 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2006-09-21 16:21 |只看该作者
少了一个括号
}elsif($choice_1 = 1){
       dbmopen(my %words,"$my_dbm",0644)
         or die "无法打开或创建文件:$^E";
DAO_R: print "请输入单词。\n";
       chomp(my $word = <STDIN>);
       print "请输入意思。\n";
       chomp(my $meanning = <STDIN>);
      }

既然use strict了 就要把变量my一下 要不你的程序还会报错

论坛徽章:
0
6 [报告]
发表于 2006-09-21 16:41 |只看该作者
谢谢,
我重改了一下:
#!/usr/bin/perl   -w

use strict;
our %wrong;
our $wrong;

print  "================================================",
        "你好,这是一个背诵软件。\n",
                            "made by kid\@B_Sky\n",
        "================================================";
BEGIN: print "现在请选择:\n",
             "1---------导入\n",
             "2---------背诵\n",
             "3---------退出\n";
chomp(my $choice_1 = <STDIN>);
if ($choice_1 < 1 || $choice_1 > 3){
       print "请仔细看说明。\n";
}elsif($choice_1 == 1){
       my @my_words_dbm = glob "\*\.dir";
       if (@my_words_dbm){
              print "请选择你的单词记录文件:\n",
                    " @my_words_dbm\n";
       }else{
              print "请给你的单词文件起名。\n";
       }
       chomp(our $my_dbm = <STDIN>);
       dbmopen(my %words,"$my_dbm",0644)
         or die "无法打开文件$my_dbm :$^E";
DAO_R: print "请输入单词。\n";
       chomp(my $word = <STDIN>);
       print "请输入意思。\n";
       chomp(my $meanning = <STDIN>);
       if ($words{$word} != ""){
             print ("$word 已经有一个意思是:$words{$word},\n",
                    "现在请选择:\n",
                    "1---------添加\n",
                    "2---------修改\n"
                    );
       chomp(my $choice_2 = <STDIN>);
             if ($choice_2 < 1 || $choice_2 > 2){
                    print "请仔细看说明。\n";
             }elsif($choice_2 == 1){
                    $words{$word} .= "\n $meanning";
             }else{
                    $words{$word} = $meanning;
             }
       }else{
             $words{$word} = $meanning;
       }
       print ("请选择:\n",
              "1---------继续\n",
              "2---------退出\n"
              );
       chomp(my $choice_3 = <STDIN>);
       if ($choice_3 < 1 || $choice_3 > 2){
              print "请仔细看说明。\n";
       }elsif($choice_3 == 1){
              goto DAO_R;
       }else{
              goto BEGIN;
       }
}elsif($choice_1 == 2){
        my @my_words_dbm = glob "\*\.dir";
        if (@my_words_dbm){
              print "请选择你的单词记录文件:\n",
                    " @my_words_dbm\n";
       }else{
              print "请给你的单词文件起名。\n";
       }
        chomp(our $my_dbm = <STDIN>);
        dbmopen(my %words,$my_dbm,0644)
          or die "无法打开文件$my_dbm:$^E ";
BEI_S:  if (my ($word , $meanning) = each(%words)){
               print "请问 $word 的意思是什么?\n",
                     "用空格将各个意思分开。\n";
               if ($meanning = (<STDIN>){
                     print ("$word的意思就是 $meanning .\n",
                            "请选择: \n",
                            "1---------继续\n",
                            "2---------退出\n"
                           );
                     chomp(my $choice_4 = <STDIN>);
                     if ($choice_4 < 1 || $choice_4 > 2){
                             print "请仔细看说明。\n";
                     }elsif($choice_4 == 1){
                             goto BEI_S;
                     }else{
                             goto BEGIN;
                     }
               }else{
                            print ("很遗憾,你答错了。\n",
                                  "$word的意思是--$meanning.\n",
                                  );
                                  $wrong{$word} = $meanning ;
                                  $wrong++;
               }
        }else{
               print "已经没有单词了\n",
                     "你这次共答错了$wrong个单词。\n",
                     "要再试一试吗?\n",
                     "1----------yes\n",
                     "2----------no";
               chomp(my $choice_5 = <STDIN>);
               if ($choice_5 == 1){
                    %words = %wrong;
                    goto BEI_S;
               }else{
                    goto BEGIN;
               }
        }
}else{
        print "欢迎下次再来^_^.\n";
}
可是它还是出错。
请问怎么改?
ps:
请问这样用vim来格式化代码?
再次谢谢。

论坛徽章:
0
7 [报告]
发表于 2006-09-21 16:47 |只看该作者
现在的报错?

论坛徽章:
0
8 [报告]
发表于 2006-09-21 16:56 |只看该作者
是的,
调试器说:
syntax error.
if ($meanning = (<STDIN>){

}else{
两行
请问怎么改。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 2006-09-21 18:21 |只看该作者
原帖由 kid@B_Sky 于 2006-9-21 16:56 发表
是的,
调试器说:
syntax error.
if ($meanning = (<STDIN>){

}else{
两行
请问怎么改。

少了半个圆括号?

求职 : 网络信息安全
论坛徽章:
0
10 [报告]
发表于 2006-09-22 00:25 |只看该作者
呵呵,请问楼主是用记事本写 Perl 程序吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP