我的输出不保存到hi.txt
open(my $fh, '>', 'C:\Users\yukari\Desktop\hi.txt');
$x = <STDIN>;
if ($x =~ /(.+) (.+)/)
{
print " $2 ,";
print " $1\n";
print $fh = "$2, $1 \n" ;
close $fh;
}
答案 0 :(得分:-2)
你能回忆一下编码吗,你可以很好地逮捕几个问题
open(my $fh, '>', "hi.txt");
$x = <STDIN>;
#1. You should do the chomp whenever getting the values from user
chomp($x);
if ($x =~ /(.+) (.+)/)
{
print " $2 ,";
print " $1\n";
#2. No need to store the variable in the FILEHANDLE
print $fh "$2, $1 \n" ;
close $fh;
}
感谢。