我想要得到的内容https://translate.google.cn,然而,Cro::HTTP::Client和HTTP::UserAgent刚刚stucks,并WWW获取内容,我不知道为什么.如果我更改$url为https://perl6.org,所有三个模块都可以正常工作:
my $url = "https://translate.google.cn";
use Cro::HTTP::Client;
my $resp = await Cro::HTTP::Client.new(
headers => [
User-agent => 'Cro'
]
).get($url);
say await $resp.body-text();
use HTTP::UserAgent;
my $ua = HTTP::UserAgent.new;
$ua.timeout = 30;
my $response = $ua.get($url);
if $response.is-success {
say $response.content;
} else {
die $response.status-line;
}
)
use WWW;
say get($url)
Run Code Online (Sandbox Code Playgroud)
我错过了sonething吗?谢谢你的建议.
我在我的macOS v10.13(High Sierra)上安装了DBIish:
zef install DBIish
Run Code Online (Sandbox Code Playgroud)
我的测试脚本是:
use v6;
use DBIish;
my $host='xxx.xx.xxx.xxx';
my $password='abc@123';
my $dbh = DBIish.connect('mysql', :host, :port(3306),
:database<ald_xinen>, :user<aldwx>, :$password);
my $sth = $dbh.do(q:to/STATEMENT/);
DROP TABLE IF EXISTS nom
STATEMENT
$sth = $dbh.do(q:to/STATEMENT/);
CREATE TABLE nom (
name varchar(4),
description varchar(30),
quantity int,
price numeric(5,2)
)
STATEMENT
$sth.finish;
$dbh.dispose;
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它得到了这个:
This type cannot unbox to a native string: P6opaque, Bool
in block at /Users/ohmycloud/.rakudobrew/moar-nom/install/share/perl6/site/sources/F2D45FC1BC0A15B4C8511E3A864F1FC1C3F269BB (DBIish) line 41
in any at /Users/ohmycloud/.rakudobrew/moar-nom/install/share/perl6/site/precomp/D3F1031B6C577F31F20F165D75D09B8D4CFEDE2F.1507566035.94084/F2/F2D45FC1BC0A15B4C8511E3A864F1FC1C3F269BB line 1
in method CALL-ME …Run Code Online (Sandbox Code Playgroud) 我想使用a生成一个json行Class,我会覆盖该gist方法,以便它将打印出我想要的内容:
my $ak = '7111ac873c9dcd5fc335ded47630d050';
my $st = '1523451601875';
my $ifo = 'true';
my $uu = "15778787898988090";
class Stay {
has $.ak is rw = '7111ac873c9dcd5fc335ded47630d050';
has $.uu is rw;
has $.ifo is rw;
has $.st is rw;
method gist() {
#return qqww/{"ev":"app","ak":"$!ak","uu":"$!uu","ifo":"$!ifo","st":"$!st"}/;
return qqww:to?EOF?;
{"ev":"app","ak":"$!ak","uu":"$!uu","ifo":"$!ifo","st":"$!st"}
EOF
}
}
say Stay.new(uu => $uu, ifo => $ifo, st => $st);
Run Code Online (Sandbox Code Playgroud)
但失败了:
===SORRY!=== Error while compiling /Users/ohmycloud/Desktop/stay.pl6
Confused
at /Users/ohmycloud/Desktop/stay.pl6:18
------> {"ev":?"app","ak":"$!ak","uu":"$!uu","ifo":"$!i
expecting any of:
colon pair
Run Code Online (Sandbox Code Playgroud)
我想要的是: …
在 Julia 中,您可以像这样按月生成日期范围:
julia> dr = Date(2014,1,29):Dates.Month(1):Date(2014,07,29)
Date("2014-01-29"):Month(1):Date("2014-07-29")
julia> collect(dr)
7-element Array{Date,1}:
2014-01-29
2014-02-28
2014-03-29
2014-04-29
2014-05-29
2014-06-29
2014-07-29
Run Code Online (Sandbox Code Playgroud)
Date(2014,1,29)是开始日期,Dates.Month(1)是步骤,Date(2014,07,29)是结束日期。
Raku后面有一个方法,但是在自定义生成器中使用时,会导致无限范围:
lazy my @dates = Date.new('2014-01-29'), Date.new('2014-02-28'), { $^a.later(:1month) } ... Date.new('2014-07-29')
Run Code Online (Sandbox Code Playgroud)
如果我在...运算符的右侧使用* >= Date.new('2014-07-29')而不是,它会起作用:Date.new('2014-07-29')
lazy my @a = Date.new('2014-01-29'), Date.new('2014-02-28'), { $^a.later(:1month) } ... * >= Date.new('2014-07-29')
2014-01-29
2014-02-28
2014-03-28
2014-04-28
2014-05-28
2014-06-28
2014-07-28
2014-08-28
Run Code Online (Sandbox Code Playgroud)
为什么自定义生成器{ $^a.later(:1month) }在{ $^a.later(:1month) } ... Date.new('2014-07-29') …
我是Perl 6的新手.我的Atom编辑器中有以下代码,但我仍然不明白它是如何工作的.我复制了以下代码,正如doc.perl6.org所说,但它似乎无法正常工作.所以我把代码更改为:
use v6;
class HTTPHeader { ... }
class HTTPHeader does Associative {
has %!fields handles <self.AT-KEY self.EXISTS-KEY self.DELETE-KEY self.push
list kv keys values>;
method Str { say self.hash.fmt; }
multi method EXISTS-KEY ($key) { %!fields{normalize-key $key}:exists }
multi method DELETE-KEY ($key) { %!fields{normalize-key $key}:delete }
multi method push (*@_) { %!fields.push: @_ }
sub normalize-key ($key) { $key.subst(/\w+/, *.tc, :g) }
method AT-KEY (::?CLASS:D: $key) is rw {
my $element := %!fields{normalize-key $key};
Proxy.new(
FETCH => …Run Code Online (Sandbox Code Playgroud)