小编dax*_*xim的帖子

如何显示值的类型层次结构?

在Perl5和Moose中,线性isa线性化isa有助于理解类层次结构.

WHAT方法显示了值的具体类型:

> 42.WHAT
(Int)
Run Code Online (Sandbox Code Playgroud)

我该如何表现出类似的东西

> 42.hypothetical-type-hierarchy
(Int) ? is (Cool) ? is (Any) ? is (Mu)
      ? does (Real) ? does (Numeric)
Run Code Online (Sandbox Code Playgroud)

...可能还有每个消费角色的更多行?


编辑:具有两个角色的示例

class Beta {}
role Delta {}
role Gamma does Delta {}
role Eta {}
role Zeta does Eta {}
role Epsilon does Zeta {}
class Alpha is Beta does Gamma does Epsilon {}

# (Alpha) ? is (Beta)
#         ? does (Gamma) ? does (Delta)
#         ? does (Epsilon) …
Run Code Online (Sandbox Code Playgroud)

perl6 mop

7
推荐指数
1
解决办法
117
查看次数

如何防止DBIx :: Class :: Schema :: Loader在Catalyst中自动添加InflateColumn :: DateTime?

我正在使用CatalystDBIx :: Class :: Schema :: Loader在Catalyst中创建我的模型,如下所示:

script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static overwrite_modifications=1 components=EncodedColumn dbi:mysql:mydb mydb pass
Run Code Online (Sandbox Code Playgroud)

不幸的是,加载器自动设置InflateColumn::DateTime为默认组件,我不想要.我想要数据库中的原始值.

__PACKAGE__->load_components("InflateColumn::DateTime", "EncodedColumn");
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何防止这种情况?

perl catalyst dbix-class

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

在Web :: Scraper的语法中{}的含义是什么?

我对Perl语法感到困惑.这是关于Web :: Scraper的一个例子.

my $t = scraper {
    process "li", "list[]" => "TEXT";
};
print ref($tweets), "\n";
Run Code Online (Sandbox Code Playgroud)

输出:

Web::Scraper
Run Code Online (Sandbox Code Playgroud)

我无法理解花括号的含义.如果scraper是一个函数,那么为什么要使用{}而不是()

perl

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

如何递归遍历嵌套哈希数据结构?

对于我来说,我看起来像一个简单的概念问题.在努力寻找Web和Stack Overflow上的类似问题后,我找不到类似的东西,所以我想我可以问你.

我正在构建一个深度嵌套的哈希数据结构的哈希.深度可以是10-20倍.为了这个问题,我只列出深度一.

我无法以递归方式遍历Perl中的示例哈希.我也包括了我的代码.

它给了我以下错误:

在使用"严格参考"时,不能使用字符串("1")作为HASH参考

很明显:我的哈希必然会有一些值为1的键.我无法避免它们.

$VAR1 = {
    'Eukaryota' => {
        'Rhodophyta'         => {'count' => 5},
        'Alveolata'          => {'count' => 16},
        'stramenopiles'      => {'count' => 57},
        'count'              => 155,
        'Glaucocystophyceae' => {'count' => 1},
        'Cryptophyta'        => {'count' => 18},
        'Malawimonadidae'    => {'count' => 1},
        'Viridiplantae'      => {'count' => 57},
    },
    'Bacteria' => {
        'Cyanobacteria'       => {'count' => 1},
        'Actinobacteria'      => {'count' => 4},
        'count'               => 33,
        'Proteobacteria'      => {'count' => 25},
        'Deinococcus-Thermus' => {'count' …
Run Code Online (Sandbox Code Playgroud)

recursion perl hash

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

如何让GD :: Graph不要写最后的X标签并覆盖我的其他标签?

我设置x_label_skip跳过标签,但它仍然试图显示最后一个标签,它覆盖了另一个标签,看起来很乱.它不应该写最后一个标签.它应该跳过最后一个标签.我根据有多少数据点设置要跳过的标签数量.

这就是它的样子:

码:

my $graph = GD::Graph::lines->new(400, 500);
$graph->set(
  r_margin          => 2,
  x_label           => 'Date',
  y_label           => 'Price',
  title             => "$symbol1, $symbol2",
  dclrs             => [ qw(lred lblue lgreen lyellow lpurple cyan lorange) ],
  transparent       => 0,
  x_labels_vertical => 1,
  x_label_skip      => int ((@tmpDate * 8)/(400-50) + 1), # a function of # of data points, each label 8px. More labels, more skip.
) or die $graph->error;
Run Code Online (Sandbox Code Playgroud)

perl gd gd-graph

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

如何获取外键而不是对象的值?

我有两张桌子,book而且language; book belongs_to language通过language列来说明它所使用的语言.该language表只是language列.

我想做$book->language并获取语言字符串,而无需从language表中获取语​​言.有没有办法做到这一点?

我怀疑这是关于回归的背景.我应该做一些过载,说:

use overload "language_string" => sub {
  my $self = shift;
  return $self->language;
}, fallback => 1;
Run Code Online (Sandbox Code Playgroud)

但在那种情况下,我当然还在掌握语言.

perl dbix-class

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

如何在有向图中找到从源到汇的所有路径?

我想找到从源到汇的所有路径.预期:

(3 11 17 24 32 39 45)
(3 11 18 26 33 39 45)
(3 11 18 26 33 40 46)
(3 11 18 26 33 40 47)
(3 11 19 27 33 39 45)
(3 11 19 27 33 40 46)
(3 11 19 27 33 40 47)
(3 11 19 27 34 40 46)
(3 11 19 27 34 40 47)
(6 12 20 27 33 39 45)
(6 12 20 27 33 40 46)
(6 12 …
Run Code Online (Sandbox Code Playgroud)

perl graph-theory

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

如何抽象多个嵌套循环?

给定,将数组切成p大小≥1的部分:

my @a = 'A'..'F';

# p = 1
my @p1 = [@a];
# ["A" .. "F"]

# p = 2
my @p2;
for my $x (0..@a-2) {
    push @p2, [
        [@a[0..$x]],
        [@a[$x+1..@a-1]],
    ];
}
# [["A"], ["B" .. "F"]],
# [["A", "B"], ["C" .. "F"]],
# [["A", "B", "C"], ["D", "E", "F"]],
# [["A" .. "D"], ["E", "F"]],
# [["A" .. "E"], ["F"]],


# p = 3
my @p3;
for my $x (0..@a-3) {
    for my $y ($x+1..@a-2) { …
Run Code Online (Sandbox Code Playgroud)

perl functional-programming

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

如何通过克隆填充Callable属性?

class Foo {
    has &.bar;
    has @.quux is required;
    method clone { nextwith :quux(@!quux.clone) };
    # as per <https://docs.perl6.org/type/Mu#method_clone>
};
my $f = Foo.new(quux => []);
my $f-clone = $f.clone(bar => sub { die });
# Foo.new(bar => Callable, quux => [])
Run Code Online (Sandbox Code Playgroud)

但应该是

Foo.new(bar => sub { #`(Sub|94789546929784) ... }, quux => [])
Run Code Online (Sandbox Code Playgroud)

添加:bar(&!bar.clone)nextwith呼叫没有帮助.

perl6

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

您如何自定义文本分割以使图不间断?

作品:

#!/usr/bin/env python3
from uniseg.graphemecluster import grapheme_clusters
def albanian_digraph_dh(s, breakables):
    for i, breakable in enumerate(breakables):
        if s.endswith('d', 0, i) and s.startswith('h', i):
            yield 0
        else:
            yield breakable

print(list(grapheme_clusters('dhelpëror', albanian_digraph_dh)))
#['dh', 'e', 'l', 'p', 'ë', 'r', 'o', 'r']
Run Code Online (Sandbox Code Playgroud)

需要改进/定制:

perl -C -Mutf8 -mUnicode::GCString -E'
    say join " ", Unicode::GCString
        ->new("dhelpëror")->as_array
'
#d h e l p ë r o r

perl6 -e'"dhelpëror".comb.say'
#(d h e l p ë r o r)
Run Code Online (Sandbox Code Playgroud)

注意:编写自己的细分(几乎可以保证不会正确实现UAX#29)算是避免问题的方法。

unicode perl perl6 text-segmentation raku

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