#!/usr/bin/perl
#use strict; use warnings;
my $file = $ARGV[0];
my $up = 0+ ($ARGV[1] || 0);
my $counter = 0;
if( $up==0 ){
# 見るだけ
if( open( my $fh, "$file" ) ){
flock($fh,1);
$counter = <$fh> || 0;
$counter += 0;
close($fh);
}
}else{
# 足し算する
if( open( my $fh, "+>> $file" ) ){
flock($fh,2);
seek($fh,0,0);
$counter = <$fh> || 0;
$counter += $up;
truncate($fh,0);
print $fh "$counter\n";
close($fh);
}
}
print "$counter\n";
SH4マシンだと、use strict; use warnings; を入れるとスピードが遅くなる。
これが入ってるだけでだいたい0.4秒くらい遅延する。微妙に致命傷なので困る。