con*_*con 1 parallel-processing perl
我有一个可以在 Perl < 5.36 上运行良好的脚本:
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use autodie ':all';
use Parallel::ForkManager;
sub execute {
my $command = shift;
print "Executing Command: $command\n";
if (system($command) != 0) {
my $fail_filename = "$0.fail";
print "$command failed.\n";
die;
}
}
sub run_parallel {
my $cmd = shift;
my $manager = new Parallel::ForkManager(2);
foreach my $command (@{ $cmd }) {
$manager->start and next;
execute( $command );
$manager->finish;
}
$manager->wait_all_children;#necessary after all lists
}
my @commands = ('echo "a"','echo "b"','echo "c"','which ls','which rm');
run_parallel(\@commands);
Run Code Online (Sandbox Code Playgroud)
但是当我对 5.36 进行细微更改时:
#!/usr/bin/env perl
use 5.036;
use warnings FATAL => 'all';
use autodie ':all';
use Parallel::ForkManager;
sub execute {
my $command = shift;
print "Executing Command: $command\n";
if (system($command) != 0) {
my $fail_filename = "$0.fail";
print "$command failed.\n";
die;
}
}
sub run_parallel {
my $cmd = shift;
my $manager = new Parallel::ForkManager(2);
foreach my $command (@{ $cmd }) {
$manager->start and next;
execute( $command );
$manager->finish;
}
$manager->wait_all_children;#necessary after all lists
}
my @commands = ('echo "a"','echo "b"','echo "c"','which ls','which rm');
run_parallel(\@commands);
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Bareword found where operator expected at debug.pl line 20, near "new Parallel::ForkManager"
Run Code Online (Sandbox Code Playgroud)
我所切换的是use 5.036
与 perl 5.36不Parallel::ForkManager兼容还是我做错了什么?
Perl v5.36 withuse v5.36关闭间接对象表示法,其中方法位于调用者之前:
my $p = new Some::Module; # indirect object notation
my $p = Some::Module->new(); # what you should do
Run Code Online (Sandbox Code Playgroud)
如果这在短期内对您来说不方便,您可以使用require最低版本,这样您仍然可以通过以下方式关闭这些功能use v5.36:
require v5.36;
Run Code Online (Sandbox Code Playgroud)
如果您实际上并不使用 v5.36 功能,还可以考虑要求您的代码实际需要的最低版本。在您的代码片段中,我没有立即看到任何最低版本要求(除了 Perl 5 之外)。
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |