【发布时间】:2015-02-27 10:17:52
【问题描述】:
我尝试了下面的代码sn-p,seek函数似乎不起作用。
funct("ls -ltr /scratch/dummy/dum*");
sub funct {
print "\nRecording\n";
open(SENSOR_LIST1, "$_[0] |") || die "Failed to read sensor list: $!\n";
for $sensor_line1 (<SENSOR_LIST1>) {
print "$sensor_line1";
}
my $pos = tell SENSOR_LIST1;
print "\nposition is $pos"; #Here the position is 613
print "\nRecording again";
seek (SENSOR_LIST1, SEEK_SET, 0);
$pos = tell SENSOR_LIST1; # Here again the position is 613, even after a seek
print "\nposition now is $pos";
for $sensor_line1 (<SENSOR_LIST1>) {
print "$sensor_line1";
}
close SENSOR_LIST1;
}
注意:所有的 seek 变体都不起作用。
输出:
即使在搜索之后位置也不会改变。它仍然在 613 中。
你们能检查一下并告诉我这里有什么问题吗?
谢谢。
【问题讨论】:
标签: perl file-handling