如果没有为perl脚本提供文件名,则寻找使用DATA句柄的方法.
我对perl不是很熟练.
就像是:
use strict;
use warnings;
use autodie;
use diagnostics;
my $fd;
if( $ARGV[0] && -f $ARGV[0] ) {
open $fd, "<", $ARGV[0];
} else {
$fd = "DATA"; #what here?
}
process($fd);
close($fd); #closing the file - or the DATA handle too?
sub process {
my $handle = shift;
while(<$handle>) {
chomp;
print $_,"\n";
}
}
__DATA__
default content
Run Code Online (Sandbox Code Playgroud)