通过典型的slurp作品从DATA读取.尝试使用DATA作为我可以进行搜索的文件句柄是行不通的.有人能够指出我必须犯的明显错误吗?
码:
#!/usr/bin/env perl use strict; use warnings; if ($ARGV[0] eq 'seek' ) { my $log_fh = \*DATA; $log_fh->seek(64,0); print "\n-- 64 --\n",join ("",<$log_fh> ); } else { while (<DATA>) { print $_; } } exit; __DATA__ 01234567890123456789 1234567890123456789 1234567890123456789 12 X <- That X is the 64th char in this file. Y <- That Y is the 106th char in this file. junk more junk. bye! $perl file_from_data.pl slurp 01234567890123456789 1234567890123456789 1234567890123456789 12 X <- That X is the 64th char in this file. Y <- That Y is the 106th char in this file. junk more junk. bye!
运行while()循环:
$perl file_from_data.pl slurp 01234567890123456789 1234567890123456789 1234567890123456789 12 X <- That X is the 64th char in this file. Y <- That Y is the 106th char in this file. junk more junk. bye!
运行seek(),它似乎不是从DATA开始,而是脚本的开始:
$perl file_from_data.pl seek -- 64 -- 'seek' ) { my $log_fh = \*DATA; $log_fh->seek(64,<$log_fh> ); } else { while (<DATA>) { print $_; } } exit; __DATA__ 01234567890123456789 1234567890123456789 1234567890123456789 12 X <- That X is the 64th char in this file. Y <- That Y is the 106th char in this file. junk more junk. bye!
这是一个旧的Perl:
$perl -v This is perl 5,version 16,subversion 3 (v5.16.3) built for x86_64-linux- thread-multi