寻求功能不在perl中工作

Hel*_*rld 3 perl file-handling

我尝试了下面的代码片段,搜索功能似乎不起作用.

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;
}
Run Code Online (Sandbox Code Playgroud)

注意:所有搜索变体都不起作用.

输出:

即使在寻求之后,该位置也不会改变.它仍然在613.

你们可以检查并告诉我这里的问题是什么?

谢谢.

Ed *_*eal 6

你不能在管道上寻找.

使用临时文件或将数据存储在内存中.

您选择最佳解决方案