小编cst*_*mas的帖子

如何在不锁定perl的情况下拖尾日志文件

这就是我现在正在做的事情,但它会锁定文件.

#!/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)

windows perl locking file tail

6
推荐指数
1
解决办法
3395
查看次数

如何将运算符传递给Perl子例程?

我有一个名为"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)

perl operators subroutine

1
推荐指数
1
解决办法
523
查看次数

标签 统计

perl ×2

file ×1

locking ×1

operators ×1

subroutine ×1

tail ×1

windows ×1