我如何使用__DATA__
两次?
#!/usr/local/bin/perl
use warnings;
use 5.012;
while ( <DATA> ) {
print;
}
while ( <DATA> ) {
chomp if $. == 1;
print scalar reverse;
print "\n" if eof;
}
__DATA__
one
two
three
four
five
six
我如何使用__DATA__
两次?
#!/usr/local/bin/perl
use warnings;
use 5.012;
while ( <DATA> ) {
print;
}
while ( <DATA> ) {
chomp if $. == 1;
print scalar reverse;
print "\n" if eof;
}
__DATA__
one
two
three
four
five
six
tell()
和seek()
操作。(虽然我相信如果你有perl 5.10或更高版本,你可以dup DATA
文件句柄而不是共享原始的DATA
文件句柄并在其中来回查找。)my @data;
while(<DATA>){
push @data, $_;
}