我有这个脚本
#!/usr/bin/perl
use strict;
use warnings;
use yy;
my $data = [
["aax", "ert", "ddd"],
["asx", "eer", "kkk"],
["xkk", "fff", "lll"],
["xxj", "vtt", "lle"],
];
use Test::More tests => 4;
is(yy::type1_to_type2(\$data, 'aax'), 'ert');
is(yy::type1_to_type3(\$data, 'asx'), 'kkk');
is(yy::type2_to_type3(\$data, 'fff'), 'lll');
is(yy::type3_to_type1(\$data, 'lle'), 'xxj');
Run Code Online (Sandbox Code Playgroud)
它使用这个模块
package yy;
sub typeX_to_typeY {
my ($x, $y, $data, $str) = @_;
foreach (@$data) {
if ($_->[$x - 1] eq $str) {
return $_->[$y - 1];
}
}
return;
}
sub type1_to_type2 { typeX_to_typeY(1, 2, @_) } …
Run Code Online (Sandbox Code Playgroud) 我有这个代码有效
my @new = keys %h1;
my @old = keys %h2;
function(\@new, \@old);
Run Code Online (Sandbox Code Playgroud)
但是可以在不必先声明变量的情况下完成吗?
function
必须将其参数作为参考.
我想迭代服务器端的哈希,并使用JSON以排序顺序将其发送到客户端.
我的问题是:
当我在我的foreach
-loop中并且具有键和复杂值时(请参阅底部的哈希值),如何将其插入到JSON字符串中?
我就是这样做的
use JSON;
my $json = JSON->new;
$json = $json->utf8;
...
# use numeric sort
foreach my $key (sort {$a <=> $b} (keys %act)) {
# somehow insert $key and contents of $act{$key} into JSON here
}
# my $json_string;
# my $data = $json->encode(%h);
# $json_string = to_json($data);
# # return JSON string
# print $cgi->header(-type => "application/json", -charset => "utf-8");
# print $json_string;
Run Code Online (Sandbox Code Playgroud)
print Dumper \%act
看起来像这样
$VAR1 = {
'127' => { …
Run Code Online (Sandbox Code Playgroud) 在构建网站时,必须决定在用户登录时如何存储会话信息.
将每个会话存储在自己的文件中与将其存储在数据库中的优缺点是什么?
我想创建一个名为的用户webapp
,可以访问webdb
使用以下权限调用的数据库
Select, Insert, Update, Delete, Create, Drop, References, Index, Alter, Lock_Tables
Run Code Online (Sandbox Code Playgroud)
我这样创建了数据库
mysql -u root -p -e 'create database webdb'
Run Code Online (Sandbox Code Playgroud)
如何从命令行创建这样的用户?
由于某种原因我得到
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
Run Code Online (Sandbox Code Playgroud)
从两个参数到crypto.timingSafeEqual(a, b)
.
我也尝试过
const a = Buffer.from(signature, 'utf8').toString('base64');
const b = Buffer.from(expectedSignature, 'utf8').toString('base64');
Run Code Online (Sandbox Code Playgroud)
我得到同样的错误。
问题
谁能弄清楚为什么参数不是缓冲区?
const express = require("express");
const bodyParser = require("body-parser");
const crypto = require('crypto');
const secret = "x";
const app = express();
const PORT = 8080;
app.use(bodyParser.json());
function isSigOk(request, secret) {
// calculate the signature
const expectedSignature = "sha256=" …
Run Code Online (Sandbox Code Playgroud) 我有这个代码
#!/usr/bin/perl
use warnings;
use strict;
use Net::LDAP;
use Data::Dumper;
my $dn="CN=...";
my $password="xxx";
my $ldap = Net::LDAP->new('example.com') or die "$@";
my $mesg = $ldap->bind($dn, password=>$password);
if ($mesg->code) { die "uuuu $mesg"; }
$mesg = $ldap->search(base => "dc=test,dc=example,dc=com", filter => "(name=LIST)",);
my $ref = $mesg->entry->get_value("member", asref => 1);
print Dumper $ref;
foreach my $string (@{$ref}) {
$string =~ /CN=(.+?),.*/;
print $1 . "\n";
}
Run Code Online (Sandbox Code Playgroud)
使用正则表达式输出CN:
aaaa
bbbb
cccc
...
Run Code Online (Sandbox Code Playgroud)
使用Dumper
可以看到结构
$VAR1 = [
'CN=aaaa,OU=test,DC=test,DC=example,DC=com',
'CN=bbbb,OU=test,DC=test,DC=example,DC=com',
'CN=cccc,OU=test,DC=test,DC=example,DC=com',
Run Code Online (Sandbox Code Playgroud)
所以我想知道是否有更多"LDAP"方式来提取这些CN,而不是使用正则表达式?
更新: …
我有很多像这样的数据
type1, type2, type3
aax, ert, ddd
asx, eer, kkk
xkk, fff, lll
xxj, vtt, lle
...
Run Code Online (Sandbox Code Playgroud)
我真的希望能够在他们之间"映射",所以我可以去
type1 -> type2
type1 -> type3
type2 -> type1
type3 -> type1
Run Code Online (Sandbox Code Playgroud)
例:
type1_to_type2(aax) should return ert
type1_to_type3(asx) should return kkk
type2_to_type3(fff) should return lll
type3_to_type1(lle) should return xxj
Run Code Online (Sandbox Code Playgroud)
应该使用什么数据结构的数据?
这些功能怎么样?
更新:所有数据都是唯一的.
Perl是否有操作员退出函数或last
函数?
sub f {
# some code here
if ($v == 10) {
# goto end of function/exit function/last
}
# some code here
}
Run Code Online (Sandbox Code Playgroud)
A goto
可以做到这一点,但它以某种方式接缝错了?
如果我输入
echo '"";"";" 01.06.2011";"7";"01.06";"-21,00";"-6.097,73";' | awk -F';' '{print $3 " " $7}'
Run Code Online (Sandbox Code Playgroud)
然后我明白了
" 01.06.2011" "-6.097,73"
Run Code Online (Sandbox Code Playgroud)
但我想要的是
" 01.06.2011" "-6097"
Run Code Online (Sandbox Code Playgroud)
应该怎么做?