2013-01-15 76 views
3

是否可以 - 在提示輸入密碼時 - 以IO::Prompter配置prompt,使輸入未添加到歷史記錄中?IO :: Prompter - 是否可以禁用歷史記錄?

#!/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; 
+0

這裏是refernce一個類似的問題:http://stackoverflow.com/questions/701078/how-can-i-enter-a-password-using-perl-and-replace -the-characters-with – squiguy

+0

如果回顯被禁用,'IO :: Prompter'如何添加到歷史記錄中? –

+0

@mugenkenichi,我加了一個例子 –

回答

1

如果你是開放使用其他模塊,我建議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; 
+0

解決方案的優點是簡單地寫$ pw = ReadLine(0); chomp $ pw? –

+0

@sid_com我想我想說清楚它會等待輸入。沒有區別。 – squiguy

相關問題