perlでファイルハンドルを切り替えたいとか

そういことがたまにあるはず
そんな時はuse FileHandle;が良いですよ
こんな感じで使うんだ
#!/usr/local/bin/perl
use FileHandle;
print "Which write file? (a or b)\n";
$in=<STDIN>;
chomp $in;
my $fh = new FileHandle;
if ($in eq "a"){
$fh -> open(">a.txt");
}
elsif ($in eq "b"){
$fh -> open(">b.txt");
}
else{
print "No File!!\n";
exit 0;
}
print $fh "foo bar!\n";
$fh -> close();


STDOUTとファイルぐらいの切り替えならこんな感じでselect使うのもありかもね
print "Write Result? (y or n)\n";
$input_keyboard2=<STDIN>;
chomp $input_keyboard2;
if ($input_keyboard2 eq "y"){
open (FH2 ,">res.txt");
select FH2;
}

デフォルトの出力に戻すには
select STDOUT