【问题标题】:IO::Prompter - Is it possible to disable history?IO::Prompter - 是否可以禁用历史记录?
【发布时间】:2013-01-15 15:29:49
【问题描述】:

是否可以在提示输入密码时从IO::Prompter 配置prompt 以不将输入添加到历史记录中?

#!/usr/local/bin/perl
use warnings;
use strict;
use 5.10.1;
use utf8;
use open qw( :encoding(UTF-8) :std );
use IO::Prompter;


my $password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;

【问题讨论】:

  • 这里有一个类似的问题供参考:stackoverflow.com/questions/701078/…
  • 如果禁用回显,IO::Prompter 会在历史记录中添加什么?
  • @mugenkenichi,我加了一个例子

标签: perl input history


【解决方案1】:

当你写这个问题时这是不可能的,但是 IO::Prompter 已被修补以包含特殊的历史记录集 NONE ,它会禁用历史记录。

第一个版本的 IO::Prompter 补丁是 0.004003。

http://search.cpan.org/~dconway/IO-Prompter-0.004003/lib/IO/Prompter.pm

my $password = prompt('Password: ', -hNONE, -echo => '');

my $force_the_user_to_type = prompt('Type something: ', -hNONE);

【讨论】:

    【解决方案2】:

    如果你愿意使用其他模块,我建议Term::ReadKey

    这是我编写的示例脚本,它将禁用回显以进行读取,读取一行并返回它接收到的内容以进行测试。

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Term::ReadKey;
    
    ReadMode 2;
    my $pw;
    print "Enter password ";
    while ( not defined( $pw ) ) {
      $pw = ReadLine(-1); 
    }
    chomp $pw;
    print "\nI got $pw entered\n";
    ReadMode 0;
    

    【讨论】:

    • 与简单地编写我的 $pw = ReadLine(0); 相比,解决方案的优势是什么?咬$pw?
    • @sid_com 我想我想明确表示它会等待输入。没有区别。
    猜你喜欢
    • 1970-01-01
    • 2020-07-26
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多