这就是我现在正在做的事情,但它会锁定文件.
#!/usr/bin/perl
use Env qw( $USERNAME );
use File::Tail;
use strict;
use warnings;
my $file = $ARGV[0];
print "$file\n";
my $fileTail = File::Tail->new( name=>$file, maxinterval=>5, tail=>-1);
my $line;
while ( defined( $line = $fileTail->read ) )
{
print $line;
}
exit;
Run Code Online (Sandbox Code Playgroud) 我有一个名为"lookup"的子程序,它在给定值的哈希中执行查找.我意识到如果我可以要求它看不到给定的值,而是小于作为参数传递的值,那将会更强大.
我可以使lookupbigger,lookupsmall等等,但我相信有更好的方法.
# lookup id according to the search criteria
sub lookup {
my( $data, $lk, $lv ) = ( @_ );
my @res;
foreach my $key (keys $data) {
my $value = $$data{$key};
next unless( defined $$value{$lk} );
# this is the line where I want to replace eq with another operator
push(@res, $key) if( $$value{$lk} eq $lv );
}
return \@res;
}
Run Code Online (Sandbox Code Playgroud)