%{$var}和之间有什么区别%$var?我试过这段代码,但是有错误:
每个引用都是test.pl第21行的实验.每个引用的参数类型必须是test.pl第21行的非反射hashref或arrayref.
use feature 'say';
%HoH = (
1 => {
husband => "fred",
pal => "barney",
},
2 => {
husband => "george",
wife => "jane",
"his boy" => "elroy",
},
3 => {
husband => "homer",
wife => "marge",
kid => "bart",
},
);
for ($i = 1; $i <= 3; $i++) {
while ( ($family, $roles) = each %$HoH{$i} ) {
say "$family: $roles";
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码运行正常:
use feature 'say';
%HoH = (
1 …Run Code Online (Sandbox Code Playgroud) 背景
我有这个路由
my $foo = $r->get('/foo/:asd')->to('Foo#bar');
在控制器中我只是用传递的param渲染一些json(借助于Mojolicious::Controller::REST)
$self->data( 'param' => $self->param('asd') );
问题
发送请求时/foo/bar,其按预期工作:
{"data":{"param":"bar"}}
但是当我试图传递一个包含a的字符串,dot例如一封电子邮件(email@email.com)时,mojo正在渲染dot为a slash.我在第一时间定义的路由不再相关,因为现在模式已更改为foo/:bar/:baz
解决方案
我被告知解决方案就在这里:https :
//github.com/kraih/mojo/blob/master/t/mojolicious/routes.t#L218
这是有道理的,但我不明白如何将其与我有.
我试图添加$foo->pattern->placeholder_start('+');到我的路由,但仍然,模式正在改变,它再次无关紧要.看起来它不会禁用与我的问题相关的点.
我尝试在$r变量上实现模式方法(这是Mojo的路由 - $self->routes)
最重要的是,我只需要为某些路由禁用点占位符或完全禁用.
谢谢
我的Perl脚本看起来像这样
#!/usr/bin/perl
system("perl ctrlc.pl");
Run Code Online (Sandbox Code Playgroud)
sub signal_handler {
print "Niraj";
}
$SIG{INT} = \&signal_handler;
print "Enter number";
my $no1 = <>;
Run Code Online (Sandbox Code Playgroud)
当我运行perl A.pl并按下Ctrl-C时,它正在检测并打印"Niraj".但是当我跑步时setsid perl A.pl,它没有检测到Ctrl-C.
我正在尝试在Perl中编写一个简单的websocket客户端:
use Protocol::WebSocket::Client;
my $client = Protocol::WebSocket->new(url => 'ws://myserver:port');
# Sends a correct handshake header
$client->connect;
# Register on connect handler
$client->on(
connect => sub {
$client->write('hi there');
}
);
# Parses incoming data and on every frame calls on_read
$client->read($reply);
print "$reply\n";
# Sends correct close header
$client->disconnect;
Run Code Online (Sandbox Code Playgroud)
如的文档中Protocol::WebSocket::Client所示,但我收到以下消息:
Can't locate object method "new" via package "Protocol::WebSocket" at ./webSocketClient.pl.
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
使用哈希时,Perl有一个非常方便的values关键字来处理哈希值.
假设我有一个双哈希,即像这样创建的东西:
my %dh = map { {$_->{id1}}{$_->{id2}} => $_ } @arr;
Run Code Online (Sandbox Code Playgroud)
然后values %dh返回一个哈希数组.要访问值,我需要这样的东西:
for my $key1 (keys %dh) {
for my $val (values %{ $dh{$key1} }) {
# stuff...
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点,避免for循环?有点像values %{ values %dh }.
此外,抱歉语法不好,我对Perl很新.
我如何grep perl数组中的某些模式并使用sed命令并将输出保存为另一个数组,如下所示
my @modifiedfiles=`echo @files | grep -E '(DataFiles|Pfgas|Startups)' | sed -e 's/.*something//g; s/#.*$//g;'`
Run Code Online (Sandbox Code Playgroud) 我正在寻找Perl警告的解决方案
"参考的关键是实验性的"
我从这样的代码得到这个:
foreach my $f (keys($normal{$nuc}{$e})) {#x, y, and z
Run Code Online (Sandbox Code Playgroud)
我在这里找到了类似StackOverflow的东西:
但我不知道如何在我的情况下应用它.
如何在不抛出此错误的情况下获取多个键控哈希的键?
我在使用Perl脚本时遇到了一些奇怪的事情.这是关于使用一个点给出不同的结果.
perlop什么都没有,或者我只是吹过它.我在看运算符优先级和关联性
print "I'd expect to see 11x twice, but I only see it once.\n";
print (1 . 1) . "3";
print "\n";
print "" . (1 . 1) . "3\n";
print "Pluses: I expect to see 14 in both cases, and not 113, because plus works on numbers.\n";
print (1 . 1) + "3";
print "\n";
print "" + (1 . 1) + "3\n";
Run Code Online (Sandbox Code Playgroud)
一开始就引用引号是一个可以接受的解决方法,以获得我想要的东西,但是这里发生的事情是我缺少的操作顺序?有什么规则可以学习?
在Perl的Getopt :: Long版本2.39我可以使用
use Getopt::Long qw( :config gnu_getopt );
GetOptions(
\my %opts,
"codon-view|c:20", # Optional value, default 20
"consensus|C:50",
...
)
Run Code Online (Sandbox Code Playgroud)
表示,如果我使用-c默认值是20放在%opts下键codon-view时-c给出,但它没有明确的价值是存在的.另一方面-c或未--codon-view提供,则哈希表中没有值存储%opts.
在2.48中,这不再有效,我在Getopt :: Long的文档中没有看到
$ perl -E'
use Getopt::Long qw( :config gnu_getopt );
say $Getopt::Long::VERSION;
GetOptions(\my %opts, "codon-view|c:20");
say $opts{"codon-view"} // "[undef]"
' -- -c
2.39
20
$ perl -E'
use Getopt::Long qw( :config gnu_getopt );
say $Getopt::Long::VERSION;
GetOptions(\my %opts, "codon-view|c:20");
say $opts{"codon-view"} …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
$url = "http://www.example.com/url.html";
$content=Encode::encode_utf8(get $url);
$nameaux = Encode::encode_utf8($DBfield);
if($content =~ />$nameaux<\/a><\/td><td class="class1">(.*?)<\/td>/ ||
$content =~ />$nameaux<\/a><\/td><td class="class2">(.*?)<\/td>/ ||
$content =~ />$nameaux<\/a><\/td><td class="class3">(.*?)<\/td>/ ) {
... more code ...
}
Run Code Online (Sandbox Code Playgroud)
这段代码很有效,除非$DBfield它等于一个包含加号(例如A + 1)的字符串$content.
有人可以解释我如何处理这个?
perl ×10
hash ×2
centos ×1
client ×1
dereference ×1
getopt-long ×1
grep ×1
mojolicious ×1
operations ×1
regex ×1
sed ×1
setsid ×1
unix ×1
websocket ×1