我有我的程序keymap
(它实际上还没有映射任何键,目前只打印出它在十六进制中看到的内容)在这里:
#!/usr/bin/env perl
use strict;
use warnings;
use Term::ReadKey;
ReadMode 4;
END {
ReadMode 0; # Reset tty mode before exiting
}
if ($ARGV[0] ~~ ["h", "-h", "--help", "help"]) {
print "Usage: (h|-h|--help|help)|(code_in codes_out [code_in codes_out]+)\nNote: output codes can be arbitrary length";
exit;
}
$#ARGV % 2 or die "Even number of args required.\n";
$#ARGV >= 0 or warn "No args provided. Output should be identical to input.\n";
my $interactive = -t STDIN;
my %mapping = @ARGV;
{
local $| = 1;
my $key;
while (ord(($key = ReadKey(0))) != 0) {
printf("saw \\x%02X\n",ord($key));
if ($interactive and ord($key) == 4) {
last;
}
}
}
这是发生的事情:
slu@new-host:~/util 20:50:20
❯ keymap a b
saw \x61
saw \x62
saw \x04
我在键盘上打字abCtrl+D。
slu@new-host:~/util 20:50:24
❯ echo "^D^Da" | keymap
No args provided. Output should be identical to input.
saw \x04
saw \x04
saw \x61
saw \x0A
Use of uninitialized value $key in ord at /Users/slu/util/keymap line 30.
我想知道这是什么意思。这仅仅是Perl“不计算”循环条件作为“设置”的情况$key
吗?我可以做些什么来抑制这里的警告吗?我知道no warnings "uninitialized";
,我不想那样。