現在、いくつかのスクリプトを csh から perl に翻訳しています。次のスイッチ コントロールを持つスクリプトを 1 つ見つけました。
#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>);
}
}
Return キーを押すと、必要なオプションが端末に出力されます。ただし、STDIN に任意のオプション (a、h、d など) を入力すると、応答がありません。retirn に入ると、期待どおりに「h 無視されました」というメッセージが端末に出力されます。
何か案は?