如果在perl中没有提供文件名,如何使用__DATA__句柄

Nem*_*emo 4 perl

如果没有为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)

mir*_*rod 5

$fd=\*DATA; 应该做的伎俩