2009年7月30日星期四

[PerlChina] Re: 请教关于IO::Prompt使用问题

参数加得不对。

#!/usr/bin/perl

use strict;
use warnings;
use IO::Prompt;

prompt ("print paswd: " , -te => '*') or die "Error: $!";

print "Your passwd is: '$_'\n";
print "Arguments: @ARGV\n";

exit ;

2009/7/30 Haiyan Lin <linhy0120@gmail.com>
谢谢cnhack TNT 的回复。按他的提示,第一个问题解决了。可第二个问题依然如故,下面是我调试实用程序时(有“-echo=>’*',和没“-echo =>'*'时)显示的信息。请继续指点,谢谢。
 
没有“-echo=>’*'”时,好像一切正常。调试时如下。
=====================================================================================================
Loading DB routines from perl5db.pl version 1.3
Editor support available.
 
Enter h or `h h' for help, or `man perldebug' for more help.
 
main::(ssr2Ref.pl:8):   $_ = join (" ", @ARGV) ;
  DB<1> b 100                                                                  
  DB<2> c                                                                      
main::(ssr2Ref.pl:100): my $passwd = prompt("Password for '$user' at '$db': ", -tty);
  DB<2> n                                                                      
Password for 'linhy' at 'physicalMap:localhost': Not_my_passwd_here
main::(ssr2Ref.pl:101): my $dbh = DBI->connect("dbi:mysql:$db",$user, "$passwd") or die "$DBI::errstr" ;
  DB<2>
=====================================================================================================
 
有“-echo=>’*'”时,好像也能工作,但会多一下警告信息(见下面红色加粗部分)。
=====================================================================================================
Loading DB routines from perl5db.pl version 1.3
Editor support available.
 
Enter h or `h h' for help, or `man perldebug' for more help.
 
main::(ssr2Ref.pl:8):   $_ = join (" ", @ARGV) ;
  DB<1> b 100                                                                  
  DB<2> c                                                                      
main::(ssr2Ref.pl:100): my $passwd = prompt("Password for '$user' at '$db': ", -tty,-echo => '*');
  DB<2> n                                                                      
Use of uninitialized value $_ in pattern match (m//) at /usr/local/lib/perl5/site_perl/5.10.0/IO/Prompt.pm line 91, <SSRFILE> line 4454.

 at /usr/local/lib/perl5/site_perl/5.10.0/IO/Prompt.pm line 91
        IO::Prompt::_get_prompt('HASH(0x9d66b14)', 'Password for \'linhy\' at \'physicalMap:localhost\': ', '-tty', '-echo', '*') called at /usr/local/lib/perl5/site_perl/5.10.0/IO/Prompt.pm line 174
        IO::Prompt::prompt('Password for \'linhy\' at \'physicalMap:localhost\': ', '-tty', '-echo', '*') called at ssr2Ref.pl line 100

Password for 'linhy' at 'physicalMap:localhost': **************************************************************************************
main::(ssr2Ref.pl:102): my $dbh = DBI->connect("dbi:mysql:$db",$user, "$passwd") or die "$DBI::errstr" ;
  DB<2>
=====================================================================================================
----- Original Message -----
From: cnhack TNT
Sent: Thursday, July 30, 2009 1:34 AM
Subject: [PerlChina] Re: 请教关于IO::Prompt使用问题

prompt() 加上 -tty 参数,如下:
--------
prompt ("print paswd: ", -tty ) or die "Error: $!";

2009/7/29 linhy <linhy0120@gmail.com>
大家好。我学习perl没有多久。我在使用模块“IO::Prompt"的时候碰到两个对我来说是“未解之谜”的问题(^_^)。请大家指点一下。谢
谢。问题描述如下。
Hello! Everyone. I'm a newbie in perl. I have encountered two problems
that puzzling me. Could you give me some suggestions. Thanks.  The
problems I encountered are:

我用的操作系统是Fedor core 10 (linux). Perl 的版本是v5.10.0。
The OS I used is Linux (Fedor core 10). The version of perl is
"v5.10.0"

问题一:不加参数好像正常,但如果加一下参数的话,会出现提示“Can't open add: No such file or
directory at iotry1.pl line 7“  代码和运行结果如下:
Question 1: It seems work normaly without anything except script name,
but warning “Can't open add: No such file or directory at iotry1.pl
line 7“ will appear on screen when something following script name.
The code and running resuls are:

======================================================
 [linhy@genome2 BatchPrimer3.extension]$ more iotry1.pl
#!/usr/bin/perl -w
#
use strict;
use warnings;
use IO::Prompt;

prompt ("print paswd: " ) or die "Error: $!";
print "You passwd is: '$_'\n";

[linhy@genome2 BatchPrimer3.extension]$ perl iotry1.pl
print paswd: hello
You passwd is: 'hello'
[linhy@genome2 BatchPrimer3.extension]$ perl iotry1.pl some arguments
Can't open some: No such file or directory at iotry1.pl line 7
[linhy@genome2 BatchPrimer3.extension]$
=======================================================


问题二: 在"prompt"中加“-echo => '*' "后,虽然可以工作,但是会给出警告:“Use of Uninitialized
value $_ in pattern match (m//) at /usr/local/lib/perl5/sit_perl/
5.10.0/IO/Prompt.pm”代码和结果如下:
Question 2: When adding option "-echo", it can work, but message "Use
of Uninitialized value $_ in pattern match (m//) at /usr/local/lib/
perl5/sit_perl/5.10.0/IO/Prompt.pm” will appear. The code  and running
results are:

 ===================================================
[linhy@genome2 BatchPrimer3.extension]$ more iotry2.pl
#!/usr/bin/perl -w
#
use strict;
use warnings;
use IO::Prompt;

prompt ("print paswd: " ,
       -echo => '*') or die "Error: $!";

print "You passwd is: '$_'\n";

exit ;

[linhy@genome2 BatchPrimer3.extension]$ perl iotry2.pl
Use of uninitialized value $_ in pattern match (m//) at /usr/local/lib/
perl5/site_perl/5.10.0/IO/Prompt.pm line 91.
print paswd: *****
You passwd is: 'hello'
[linhy@genome2 BatchPrimer3.extension]$

====================================================





--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
 要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
 要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛

-~----------~----~----~----~------~----~------~--~---

没有评论: