在 Perl6 中更改 Data::Printer 中的参数 [英] Altering parameters in Data::Printer in Perl6

查看:47
本文介绍了在 Perl6 中更改 Data::Printer 中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Data::Printer 在 Perl6 中打印数据,这是一个很棒的包,但我正在尝试更改参数,但我无法更改.

I'm printing data in Perl6 with Data::Printer which is a spectacular package, but I am trying to alter parameters and I am not able to.

例如,我想要:

HG00112 {
    gained_site                    {
        9:10162   0,
        9:10272   var{HG00112}{gained_site}{9:10162},
        9:10326   var{HG00112}{gained_site}{9:10162},
        ...
}(tied to Perl6::Hash)

看起来像

HG00112 {
    gained_site                    {
        9:10162   0,
        9:10272   0,
        9:10326   0,
        ...
}(tied to Perl6::Hash)

为了更容易阅读(我不关心 特别绑定到 Perl6::Hash)

for easier readability (I don't care about tied to Perl6::Hash specifically)

这个哈希元素可以用 JSON 看到:

this hash element can be seen with JSON:

"HG00112": {
    "discordant_multiallelic_loss": 0,
    "concordant_hom_alt": 4,
    "discordant_het_to_alt": 0,
    "discordant_hom_alt_to_ref": 0,
    "discordant_hom_ref_to_alt": 0,
    "lost_site": 0,
    "concordant_het": 3,
    "discordant_multiallelic_gain": 0,
    "discordant_hom_alt_to_het": 0,
    "discordant_call_to_no_call": 0,
    "discordant_het_to_ref": 0,
    "concordant_hom_ref": 5,
    "concordant_site": 18,
    "discordant_no_call_to_call": 0,
    "concordant_no_call": 6,
    "concordant_multiallelic": 0,
    "gained_site": 0,
    "discordant_hom_ref_to_het": 0
}

我通常使用 use Data::Printer:from<Perl5> 加载包,并使用来自

I normally load the package using use Data::Printer:from<Perl5>, and using suggestions from

终端 ANSI 颜色不适用于 Inline::Perl5(数据::打印机)

我已经尝试在 https://metacpan.org/pod/Data 的建议下使用它::Printer ,即

I have tried using that with advice from https://metacpan.org/pod/Data::Printer , namely

use Data::Printer:from{show_tied =>0}

&use Data::Printer:fromshow_tied =>0

但都显示错误

Data::Printer"导入时出错:没有这样的标签show_tied"

Error while importing from 'Data::Printer': no such tag 'show_tied'

如何让 Data::Printer 的输出看起来像第二个代码选择,而没有丑陋的 var{...?

How can I get the output from Data::Printer to look like the second code selection, without the ugly var{...?

---编辑---

稍微改进,脚本识别选项 show_tied 但仍然没有使用它:

a slight improvement, the script recognizes the option show_tied but still doesn't use it:

我的测试脚本:

use JSON::Fast;
use Data::Printer:from<Perl5> 'show_tied', 0;

my %conc = from-json '{"HG00112": {
    "discordant_multiallelic_loss": 0,
    "concordant_hom_alt": 4,
    "discordant_het_to_alt": 0,
    "discordant_hom_alt_to_ref": 0,
    "discordant_hom_ref_to_alt": 0,
    "lost_site": 0,
    "concordant_het": 3,
    "discordant_multiallelic_gain": 0,
    "discordant_hom_alt_to_het": 0,
    "discordant_call_to_no_call": 0,
    "discordant_het_to_ref": 0,
    "concordant_hom_ref": 5,
    "concordant_site": 18,
    "discordant_no_call_to_call": 0,
    "concordant_no_call": 6,
    "concordant_multiallelic": 0,
    "gained_site": 0,
    "discordant_hom_ref_to_het": 0
}}';

p %conc;

显示几乎无用的输出:

{
    HG00112   {
        concordant_het                 3,
        concordant_hom_alt             var{HG00112}{concordant_het},
        concordant_hom_ref             var{HG00112}{concordant_het},
        concordant_multiallelic        var{HG00112}{concordant_het},
        concordant_no_call             var{HG00112}{concordant_het},
        concordant_site                var{HG00112}{concordant_het},
        discordant_call_to_no_call     var{HG00112}{concordant_het},
        discordant_het_to_alt          var{HG00112}{concordant_het},
        discordant_het_to_ref          var{HG00112}{concordant_het},
        discordant_hom_alt_to_het      var{HG00112}{concordant_het},
        discordant_hom_alt_to_ref      var{HG00112}{concordant_het},
        discordant_hom_ref_to_alt      var{HG00112}{concordant_het},
        discordant_hom_ref_to_het      var{HG00112}{concordant_het},
        discordant_multiallelic_gain   var{HG00112}{concordant_het},
        discordant_multiallelic_loss   var{HG00112}{concordant_het},
        discordant_no_call_to_call     var{HG00112}{concordant_het},
        gained_site                    var{HG00112}{concordant_het},
        lost_site                      var{HG00112}{concordant_het}
    } (tied to Perl6::Hash)
} (tied to Perl6::Hash)

推荐答案

正如我在下面介绍和链接的Q+A中解释的,你应该可以控制DP的name选项如下:

As explained in the Q+A I introduce and link below, you should be able to control DP's name option as follows:

use Data::Printer kv { name => '' }

这有望至少从丑陋的var{..."位中消除var.

This will hopefully eliminate at least the var from "the ugly var{..." bit.

如果是这样,那至少将证明您现在能够控制 DP 的选项.

And if so, that in turn will at least demonstrate that you are now able to control DP's options.

充其量,将 name 设置为 '' 将关闭整个循环参考显示.(如果没有,也许将其设置为 0?)

At best, setting name to '' will switch off the whole circular reference display. (And if not, maybe setting it to 0?)

最坏的情况是,您仍然会在循环引用的开头看到三个字母的名称"var,我想我们必须找出原因.

At worst, you'll still see the three letter "name" var at the start of the circular references and I think we'd then have to figure out why.

如果你能用 kv { name => 来评论事情是如何解决的?'' } 我们将取得进展.

If you can comment on how things worked out with kv { name => '' } we'll be making progress.

问题的关键部分,你明确不关心......特别是"((绑定到 Perl6::Hash) 位,由 DP 的 控制)show_tied 选项)仍然非常值得明确解决.如果不出意外,它涉及到尝试设置时不可避免的常见问题解答,在 Raku use 语句中,几乎 any 几乎 any 命名选项> Perl 模块.

A key part of your question that you explicitly "don't care about ... specifically" (the (tied to Perl6::Hash) bit, which is controlled by DP's show_tied option) is nevertheless very much worth clearly resolving. If nothing else, it involves what will inevitably be a FAQ when trying to set, in a Raku use statement, almost any named option of almost any Perl module.

所以我写了一个 Q+A 对来解决这个问题:在 Raku 中使用时如何关闭 Perl 5 模块 Data::Printer 的 show_tied 选项?.

So I've written a Q+A pair resolving that bit: How do I turn the Perl 5 module Data::Printer's show_tied option off when using it in Raku?.

我现在可以说的第一个也是最重要的一点是,就像 他们对您问题的评论之一,我无法重现您的问题.

The first and most important point I can make right now is that, just like @HåkonHægland++ in one of their comments on your question, I cannot reproduce your problem.

也就是说,当我运行您上次列出的测试代码时,它显示(在 ... 处省略了一些行):

That is to say, when I run your last listed test code, it displays (with some lines elided at ...):

{
    HG00112   {
        concordant_het                 3,
        concordant_hom_alt             4,
        concordant_hom_ref             5,
        concordant_multiallelic        0,
        concordant_no_call             6,
        concordant_site                18,
        discordant_call_to_no_call     0,
        ...
        discordant_no_call_to_call     0,
        gained_site                    0,
        lost_site                      0
    }
}

如您所见,没有任何丑陋"的循环引用.

As you can see, there's none of the "ugly" circular references.

这是将 show_tied 设置为关闭,根据上面链接的 Q+A.但即使保留了 show_tied,按照默认设置,我仍然得到上面的结果,只是有几个 (绑定到 Perl6::Hash) 注释.

This is with show_tied set to off, as per the above linked Q+A. But even with show_tied left on, per the default, I still get the above, just with a couple (tied to Perl6::Hash) annotations.

因此,正如@HåkonHægland++ 在他们对您的问题的另一条评论中所解释的那样,var{... 部分可能与 show_tied 无关,而是由于您未与我们共享的 JSON 数据中的循环引用.

So, as @HåkonHægland++ explained in another of their comments on your question, the var{... parts are presumably nothing to do with show_tied but rather due to circular references in your JSON data that you are not sharing with us.

简而言之,您的问题与您的数据和/或 DP 的 name 选项的使用有关,而不是它的 show_tied 选项.

In short, your problem is something about your data and/or about use of DP's name option, not its show_tied option.

我认为我们中的任何一个 Raku 人都不太可能对您的数据(可能不是由 Raku 生成的)提供帮助,但我们应该能够帮助取得进展,甚至可能解决您的问题到适当使用某些 DP 的程度选项.

I think it's unlikely any of us Raku folk can help with your data (which was presumably not generated by Raku) but we should be able to help make progress and perhaps even resolve your question to the degree it's about appropriately using some DP option.

这篇关于在 Perl6 中更改 Data::Printer 中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆