我有这个代码
#!/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)
应该使用什么数据结构的数据?
这些功能怎么样?
更新:所有数据都是唯一的.
我可以读出文本字段值,但是当我尝试找到所选的单选按钮时,我什么也得不到.
$(document).ready(function(){
$("form#create_form").submit(function() {
var title = $('#title').attr('value');
var owner = $('#owner').attr('value');
var users = $('#users').attr('value');
var groups = $('#groups').attr('value');
var begin_date = $('#begin_date').attr('value');
var end_date = $('#end_date').attr('value');
// get selected radio button
var type = '';
for (i=0; i<document.forms[0].type.length; i++) {
if (document.forms[0].type[i].checked) {
type = document.forms[0].type[i].value;
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="create-new">
<form id="create_form" name="create_form" action="" method="post">
...
<input name="type" id="type" value="individuel" type="radio" /> Individuel <br/>
<input name="type" id="type" value="course" type="radio" /> Course <br/>
<button class="n" type="submit">Create</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个看起来像的网站
其中"开始日期"和"结束日期"是日期选择器.
生成网页时,我可以在这些字段中填写值,但也可以在其中添加datepicker,清除值.
我像这样初始化datepicker
$(function() {
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
$("#from, #to").datepicker("option", "dateFormat", "dd/mm-yy");
});
Run Code Online (Sandbox Code Playgroud)
和HTML看起来像
<input class="new" type="text" id="from" name="from"/>
Run Code Online (Sandbox Code Playgroud)
如何在加载网页时让datepicker不清除表单字段值?
通常,可以下载具有登录表单的页面
wget --no-check-certificate --save-cookies cookies --keep-session-cookies \
--post-data="username=example&password=example" \
"https://example.com/index.php?title=Special:Userlogin&returntotitle="
wget --no-check-certificate --load-cookies=cookies \
--no-parent -r --level=2 -nc -E \
https://example.com/Special:Sitemap
Run Code Online (Sandbox Code Playgroud)
但是对于DekiWiki网站,如果需要登录,这不起作用.
问题接缝将在中描述 man wget
注意:如果在POST请求完成后重定向Wget,则不会将POST数据发送到重定向的URL.这是因为处理POST的URL通常会重定向到常规页面,而不希望或接受POST.这种行为是最佳的并不完全清楚; 如果它没有成功,将来可能会改变.
题
这可以使用Perl完成,例如使用HTML::TreeBuilder 3
或者HTML::TokeParser
或Mechanize
或任何其他Perl模块吗?
如果我输入
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)
应该怎么做?
当我从MySQL数据库中提取数据时,某些输出具有特殊字符,当在例如emacs中打开时,它会解码为\240
和\346
.
当在UTF-8终端中显示时,特殊字符显示为 ?
因此使用的编码接缝仅使用每个字符1个字节.
我可以看到\346
应该是æ
.
题
Perl有一个可以将这些特殊字符编码为UTF-8的模块吗?
我有这个代码
if (defined($xml->{account}->{p}) == '2') {
...
}
Run Code Online (Sandbox Code Playgroud)
这给了我这个警告
Pseudo-hashes are deprecated at a.pl line 48.
Run Code Online (Sandbox Code Playgroud)
问题是在某些情况下$xml->{account}->{p}
不存在,这就是我添加defined
功能的原因.
$xml
是一个对象,如果这有所作为?
怎么能修复,所以Perl不抱怨?
在这篇文章中,我学习了如何在服务器端编码对象,现在我想在客户端解码它.
在客户端我做
$.ajax({
type: "GET",
url: "/cgi-bin/ajax_sort.pl",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { "column" : this.id },
error: function(XMLHttpRequest, textStatus, errorThrown) {
showError('responseText: ' + XMLHttpRequest.responseText);
showError('textStatus: ' + textStatus);
showError('errorThrown: ' + errorThrown);
},
success: function(result){
if (result.error) {
showError(result.error);
} else {
var obj = jQuery.parseJSON(result);
}
}
});
Run Code Online (Sandbox Code Playgroud)
题
obj
现在是否包含已解码的JSON数据?
如果是这样,该对象看起来像服务器端(Perl的输出Data::Dumper
)
$VAR1 = {
'127' => {
'owners' => [
'm'
],
'users' => [
'hh',
'do'
],
'date_end' => '24/05-2011', …
Run Code Online (Sandbox Code Playgroud) 如果我有一个名称如下的数组.
如何打印"嗨乔和杰克和约翰"?
当数组中只有一个名称时,算法也应该有效.
#!/usr/bin/perl
use warnings;
use strict;
my @a = qw /joe jack john/;
my $mesg = "Hi ";
foreach my $name (@a) {
if ($#a == 0) {
$mesg .= $name;
} else {
$mesg .= " and " . $name;
}
}
print $mesg;
Run Code Online (Sandbox Code Playgroud)