我有一个$subscribers可能是undef 的标量,引用HASH或引用ARRAY.我已经分配了样本值$VAR1,$VAR2并$VAR3进行了测试.
我只$subscribers对它是ARRAY的引用感兴趣,其中它包含多个值.在其他情况下,我对打印任何东西都不感兴趣(例如$subscribers=$VAR2;
在Perl v5.16.2下,代码似乎运行良好; 但是,当我将它移动到运行Perl v5.8.8的目标机器时,我收到编译错误:
% ./test.pl
Type of arg 1 to keys must be hash (not private variable) at ./test.pl line 23, near "$subscribers) "
Execution of ./test.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
代码如下:
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
my $VAR1 = undef;
my $VAR2 = {'msisdn' => '1234'};
my $VAR3 = [
{'msisdn' => '1111'},
{'msisdn' => '2222'}, …Run Code Online (Sandbox Code Playgroud) 在 Kubernetes 中Kubernetes Health Check Probes,如果timeoutSeconds超过会发生什么periodSeconds?例如:
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
Run Code Online (Sandbox Code Playgroud)
Pod 什么时候会“失败”?
initialDelaySeconds+ ( periodSeconds* failureThreshold); 或者initialDelaySeconds+ ( MAX( periodSeconds, timeoutSeconds) * failureThreshold);当 Pod 成功时,同样的问题也适用。
kubernetes kubernetes-health-check readinessprobe livenessprobe
我希望Perl仅在STDOUT不相同的情况下写入STDERR.例如,如果STDOUT和STDERR都将输出重定向到终端,那么我不希望打印STDERR.
考虑以下示例(outerr.pl):
#!/usr/bin/perl
use strict;
use warnings;
print STDOUT "Hello standard output!\n";
print STDERR "Hello standard error\n" if ($someMagicalFlag);
exit 0
Run Code Online (Sandbox Code Playgroud)
现在考虑一下(这是我想要实现的):
bash $ outerr.pl
Hello standard output!
Run Code Online (Sandbox Code Playgroud)
但是,如果我重定向到一个文件,我想得到:
bash $ outerr.pl > /dev/null
Hello standard error
Run Code Online (Sandbox Code Playgroud)
和反过来相似:
bash $ outerr.pl 2> /dev/null
Hello standard output!
Run Code Online (Sandbox Code Playgroud)
如果我将两个/ err重定向到同一个文件,则只显示out:
bash $ outerr.pl > foo.txt 2>&1
bash $ cat foo.txt
Hello standard output!
Run Code Online (Sandbox Code Playgroud)
那么有没有办法评估/确定OUT和ERR是否指向相同的"事物"(描述符?)?
在Mojolicious for Perl中,有没有办法限制concurrency使用时Promise->all_settled?
在下面的例子中,我想限制concurrency=>10. 我用来sleep模拟阻塞操作:
use Mojolicious::Lite -signatures, -async_await;
helper isOdd_p => sub($self, $number)
{
return Mojo::Promise->new(sub($resolve, $reject ) {
Mojo::IOLoop->subprocess(
sub {
sleep 1;
$number % 2;
},
sub ($subprocess, $err, @res ) {
$reject->( $err ) if $err;
$reject->( @res ) if @res && $res[0]==0; # reject Even
$resolve->( @res );
})
});
};
any '/' => async sub ($c) {
$c->render_later();
my @promises = map { $c->isOdd_p($_) } …Run Code Online (Sandbox Code Playgroud) 我想将带有参数的子程序推入堆栈,但我无法弄清楚语法.考虑一个没有参数的工作示例:
#!/usr/bin/perl -w
use strict;
use warnings;
sub hi { print "hi\n"; }
sub hello { print "hello\n"; }
sub world { print "world\n"; }
my @stack;
push (@stack, \&hi );
push (@stack, \&hello);
push (@stack, \&world);
while (@stack) {
my $proc = pop @stack;
$proc->();
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时:
% ./pop-proc.pl
world
hello
hi
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,如果子程序看起来像这样:
sub mysub
{
chomp( my( $arg ) = @_ );
print "$arg\n";
}
Run Code Online (Sandbox Code Playgroud)
我想用参数推送子程序,例如:
mysub("hello");
mysub("world");
Run Code Online (Sandbox Code Playgroud)
您的意见非常感谢.
我正在尝试并行运行多个子程序(从外部系统获取数据).为了模拟,我sleep在下面的例子中使用.我的问题是:我怎样才能在Mojolicious中实现这一目标?
#!/usr/bin/perl
use Mojolicious::Lite;
use Benchmark qw(:hireswallclock);
sub add1 { my $a = shift; sleep 1; return $a+1; }
sub mult2 { my $b = shift; sleep 1; return $b*2; }
sub power { my ($x, $y) = @_; sleep 1; return $x ** $y; }
any '/' => sub {
my ( $self ) = @_;
my $n = int(rand(5));
my $t0 = Benchmark->new;
my $x = mult2($n); # Need to run in parallel
my $y = …Run Code Online (Sandbox Code Playgroud) parallel-processing perl multithreading web-services mojolicious
我无法在 macOS Big Sur 11.2.1 上构建和安装Oracle Instant Client 19.8。我收到以下错误:
Error: Can't load '/Users/x/.cpanm/work/1613898291.17798/DBD-Oracle-1.80/blib/arch/auto/DBD/Oracle/Oracle.bundle' for module DBD::Oracle: dlopen(/Users/x/.cpanm/work/1613898291.17798/DBD-Oracle-1.80/blib/arch/auto/DBD/Oracle/Oracle.bundle, 0x0002): dependent dylib '@rpath/libclntsh.dylib.19.1' not found for '/Users/x/.cpanm/work/1613898291.17798/DBD-Oracle-1.80/blib/arch/auto/DBD/Oracle/Oracle.bundle'. relative file paths not allowed '@rpath/libclntsh.dylib.19.1' at /System/Library/Perl/5.28/darwin-thread-multi-2level/DynaLoader.pm line 197.
Run Code Online (Sandbox Code Playgroud)
Big Sur 似乎没有将DYLD_LIBRARY_PATH环境变量传递给子 shell:
Your DYLD_LIBRARY_PATH env var is set to ''
WARNING: Your DYLD_LIBRARY_PATH env var doesn't include '/opt/instantclient_19_8' but probably needs to.
Run Code Online (Sandbox Code Playgroud)
我努力了:
~/Downloads/instantclient_19_8~/lib或/usr/local/libinstall_name_tool修改id并更改@rpath但得到warning: changes …在我的 Mojolicious 控制器中,我有:
my @promise;
foreach my $code (\&doit1, \&doit2,) {
my $prom = Mojo::Promise->new;
Mojo::IOLoop->subprocess(
sub {
my $r = $code->("Hello");
return $r;
},
sub {
my ($subprocess, $err, @res) = @_;
return $prom->reject($err) if $err;
$prom->resolve(@res);
},
);
push @promise, $prom;
}
Mojo::Promise
->all(@promise)
->then(
sub {
my ($result1, $result2) = map {$_->[0]} @_;
});
Run Code Online (Sandbox Code Playgroud)
这有效,我可以将参数(例如Hello)传递给我的子程序。
现在我皈依doti1()并doit2()成为帮手。所以代码看起来像:
foreach my $code (sub {$self->myhelper->doit1("Goodbye")},
sub {$self->myhelper->doit2("Good night")},
) {
my $prom = Mojo::Promise->new;
Mojo::IOLoop->subprocess( …Run Code Online (Sandbox Code Playgroud) 以下 JavaScript 代码:
'use strict';
const CryptoJS = require('crypto-js');
const plaintext = 's3cret';
const password = 'MyPassword';
//const iv = CryptoJS.lib.WordArray.random(16);
//const salt = CryptoJS.lib.WordArray.random(16);
const iv = CryptoJS.enc.Hex.parse("43c9ccba630fe1cd61fc2bdb90121c6f"); // For testing
const salt = CryptoJS.enc.Hex.parse("5c788a415851e909d9c7951717714204"); // For testing
const key = CryptoJS.PBKDF2(password, salt, {keySize: 128/32, iterations: 1000});
const b64ciphertext = CryptoJS.AES.encrypt(plaintext, key, {iv: iv}).ciphertext.toString(CryptoJS.enc.Base64);
console.log(b64ciphertext);
Run Code Online (Sandbox Code Playgroud)
crypto-js@4.2.0, 产生:
'use strict';
const plaintext = 's3cret';
const password = 'MyPassword';
//const iv = CryptoJS.lib.WordArray.random(16);
//const salt = CryptoJS.lib.WordArray.random(16);
const iv …Run Code Online (Sandbox Code Playgroud)我正在尝试从输入字符串创建一个Perl哈希,但是我遇到了原始'split'的问题,因为值可能包含引号.下面是一个示例输入字符串,以及我的(所需)结果哈希:
my $command = 'CREATE:USER:TEL,12345678:MOB,444001122:Type,Whatever:ATTRIBUTES,"ID,0,MOB,123,KEY,VALUE":TIME,"08:01:59":FIN,0';
my %hash =
(
CREATE => '',
USER => '',
TEL => '12345678',
MOB => '444001122',
Type => 'Whatever',
ATTRIBUTES => 'ID,0,MOB,123,KEY,VALUE',
TIME => '08:01:59',
FIN => '0',
);
Run Code Online (Sandbox Code Playgroud)
输入字符串具有任意长度,并且未设置键的数量.
谢谢!
-hq
perl ×9
mojolicious ×3
hash ×2
promise ×2
aes ×1
arrays ×1
async-await ×1
coderef ×1
cryptojs ×1
dbd ×1
dbi ×1
encryption ×1
io ×1
javascript ×1
kubernetes ×1
macos ×1
oracle ×1
ref ×1
regex ×1
split ×1
stderr ×1
stdout ×1
subroutine ×1
syntax ×1
unix ×1
web-services ×1