我目前正在将一些脚本从 csh 翻译成 perl。我遇到了一个具有以下开关控制的脚本
#And now some control
set get_command = h
set finish = 0
while (1)
switch ($get_command)
case "h":
case "H":
set cine_command = ""
cat << EOF
Control synchronised cine by (case insensitive):
A - A view data
B - B view data
a - accelerate
d - decelerate
r - real time heart rate
<num> - rate (frames per second)
i - toggle interpolation
s - step through (may lose a little synchronisation)
c - continue (restart) after stepping
y - reverse direction
h - help (repeat this)
f - finish (quit)
q - quit (finish)
<return> - quit
EOF
breaksw
case "":
case "f":
case "F":
case "q":
case "Q":
set cine_command = '-f'
set finish = 1
breaksw
case "a":
set cine_command = '-a'
breaksw
case "d":
case "D":
set cine_command = '-d'
breaksw
case "r":
case "R":
set cine_command = "-t $time_per_frame"
breaksw
case "i":
case "I":
set cine_command = '-i'
breaksw
case "s":
case "S":
set cine_command = "-s"
breaksw
case "c":
case "C":
set cine_command = "-c"
breaksw
case "y":
case "Y":
set cine_command = "-y"
breaksw
case '[0-9]*':
set cine_command = "-r $get_command"
breaksw
default:
echo "$get_command ignored"
set cine_command = ""
endsw
if ('$cine_command' != '') then
select_tv $FIRST_TV
cine $cine_command
select_tv $SECOND_TV
cine $cine_command
endif
#
# If we're stopping then get out of this loop.
#
if ($finish) break
echo -n "cine > "
set get_command = $<
end
我在我的系统上安装了 Perl 5.8.8,use Strict;
并且我知道在下一个 perl 版本中可能会弃用它,我尝试了以下
#Add some fine control to script
my $get_command = 'h';
my $finish = 0;
my $cine_command;
while(<>)
{
switch ($get_command)
{
case [hH] {$cine_command = "";}
print STDOUT << 'END';
Control synchronised cine by (case insensitive):
A - A view data
B - B view data
a - accelerate
d - decelerate
r - real time heart rate
<num> - rate (frames per second)
i - toggle interpolation
s - step through (may lose a little synchronisation)
c - continue (restart) after stepping
y - reverse direction
h - help (repeat this)
f - finish (quit)
q - quit (finish)
<return> - quit
END
case [fFqQ]
{
$cine_command = '-f';
$finish = 1;
}
case "a"
{
$cine_command = '-a';
}
case [dD]
{
$cine_command = '-d';
}
case [rR]
{
$cine_command = "-t $time_per_frame";
}
case [iI]
{
$cine_command = '-i';
}
case [sS]
{
$cine_command = '-s';
}
case [cC]
{
$cine_command = '-c';
}
case [yY]
{
$cine_command = '-y'
}
case /\d/
{
$cine_command = "-r $get_command";
}
else
{
print "$get_command ignored\n";
$cine_command = "";
}
if ($cine_command ne "")
{
`select_tv $FIRST_TV`;
`cine $cine_command`;
`select_tv $SECOND_TV`;
`cine $cine_command`;
}
exit if( $finish == 1);
print STDOUT "cine > \n";
chomp(my $get_command = <STDIN>);
}
}
当我按下回车键时,我会在终端上打印出所需的选项。但是,当我在 STDIN 中输入任何选项时——例如 a、h 或 d——我没有得到任何响应。当我输入 retirn - 我得到消息“h被忽略”按预期打印到终端。
有任何想法吗?