问题
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.
For example, I want:
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)
to look like
HG00112 {
gained_site {
9:10162 0,
9:10272 0,
9:10326 0,
...
}(tied to Perl6::Hash)
for easier readability (I don't care about tied to Perl6::Hash
specifically)
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
}
I normally load the package using use Data::Printer:from<Perl5>
, and using suggestions from
Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer)
I have tried using that with advice from https://metacpan.org/pod/Data::Printer , namely
use Data::Printer:from<Perl5> {show_tied => 0}
& use Data::Printer:from<Perl5> show_tied => 0
but both show the error
Error while importing from '
Data::Printer
': no such tag 'show_tied
'
How can I get the output from Data::Printer
to look like the second code selection, without the ugly var{...
?
---edit---
a slight improvement, the script recognizes the option show_tied
but still doesn't use it:
my test script:
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;
shows nearly useless output:
{
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)
回答1:
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 => '' }
This will hopefully eliminate at least the var
from "the ugly var{...
" bit.
And if so, that in turn will at least demonstrate that you are now able to control DP's options.
At best, setting name
to ''
will switch off the whole circular reference display. (And if not, maybe setting it to 0
?)
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.
If you can comment on how things worked out with kv { name => '' }
we'll be making progress.
How do I turn the Perl 5 module Data::Printer's show_tied
option off when using it in Raku?
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.
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 ugly var{...
"
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.
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.
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.
In short, your problem is something about your data and/or about use of DP's name
option, not its show_tied
option.
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.
来源:https://stackoverflow.com/questions/55799219/altering-parameters-in-dataprinter-in-perl6