小编San*_*ing的帖子

为什么"不是ARRAY参考"错误?

我有这个脚本

#!/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)

arrays perl

6
推荐指数
2
解决办法
1万
查看次数

可以在不首先声明变量的情况下进行引用吗?

我有这个代码有效

my @new = keys %h1;
my @old = keys %h2;

function(\@new, \@old);
Run Code Online (Sandbox Code Playgroud)

但是可以在不必先声明变量的情况下完成吗?

function必须将其参数作为参考.

arrays perl hash reference perl-data-structures

6
推荐指数
2
解决办法
147
查看次数

如何JSON编码哈希?

我想迭代服务器端的哈希,并使用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)

perl hash json

6
推荐指数
1
解决办法
9181
查看次数

在文件与数据库中存储会话数据的优缺点是什么?

在构建网站时,必须决定在用户​​登录时如何存储会话信息.

将每个会话存储在自己的文件中与将其存储在数据库中的优缺点是什么?

php ruby python asp.net ruby-on-rails

6
推荐指数
1
解决办法
1492
查看次数

如何创建具有有限权限的MySQL用户?

我想创建一个名为的用户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)

如何从命令行创建这样的用户?

mysql

6
推荐指数
1
解决办法
5255
查看次数

如何将 Buffer.from() 与 crypto.timingSafeEqual() 一起使用?

由于某种原因我得到

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)

javascript node.js ecmascript-6

6
推荐指数
1
解决办法
3175
查看次数

用LDAP提取CN?

我有这个代码

#!/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,而不是使用正则表达式?

更新: …

perl ldap

5
推荐指数
1
解决办法
1980
查看次数

如何在三个值之间"映射"?

我有很多像这样的数据

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 data-structures

5
推荐指数
1
解决办法
323
查看次数

功能的"最后"操作符?

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可以做到这一点,但它以某种方式接缝错了?

perl

5
推荐指数
1
解决办法
274
查看次数

如何操作awk输出?

如果我输入

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)

应该怎么做?

linux bash awk

5
推荐指数
1
解决办法
1952
查看次数