- 论坛徽章:
- 0
|
我用的是5.14
弱弱问下改成5.14,是不把say改成print就可以。
运行有结果,就输出格式不对。
#!/usr/bin/perl
#use 5.14;
use threads;
open my $d, '1.txt';
open OUT, '>3.txt';
my $s = <$d>;
chomp $s;
my ( $p, $ta, $x, $in, @th ) = ( 20, '', 0 );
my $i = int( length($s) / $p ) + 1;
for ( 1 .. $p ) {
my $sp = substr( $s, $x, $i );
$x += $i;
$in = $ta . $sp;
push @th, threads->create( \&that );
$ta = substr( $sp, -7, 7 );
}
my ( @r, %k );
push @r, $_->join for @th;
for (@r) {
my %h = %$_;
$k{$_} += $h{$_} for keys %h;
}
#say "$_\t$k{$_}" for sort keys %k;
print OUT "$_\t$k{$_}" for sort keys %k
sub that {
my %h;
for ( 0 .. length($in) - 8 ) {
$h{ substr( $in, $_, 8 ) }++;
}
return \%h;
}
回复 10# rubyish
|
|