怎么在perl代码中明确重定向输入输出
如何在perl代码中明确重定向输入输出
以前的代码都是print "xxxxx";的形式,然后在调用时重定向输出到文件。
现在要通过参数,来自动选择是打印到屏幕还是文件。
------解决方案--------------------
my $path="your file path";
my $file="your file name";
unless(open FILE,">$path/$file"){
die "can't open '$path/$build':$!";
}
output to file
print FILE "what you want";
上面就可以了
------解决方案--------------------
print HANDLE "content";
就可以重定向到HANDLE这个设备上了,可以是文件句柄或者其它的句柄!
以前的代码都是print "xxxxx";的形式,然后在调用时重定向输出到文件。
现在要通过参数,来自动选择是打印到屏幕还是文件。
------解决方案--------------------
my $path="your file path";
my $file="your file name";
unless(open FILE,">$path/$file"){
die "can't open '$path/$build':$!";
}
output to file
print FILE "what you want";
上面就可以了
------解决方案--------------------
print HANDLE "content";
就可以重定向到HANDLE这个设备上了,可以是文件句柄或者其它的句柄!