12

Perlでは巨大なハッシュを分析する必要があるので、Data::Dumperモジュールを使用してファイルに出力します。巨大なファイルなので読みづらいです。どういうわけかDumper出力をうまく印刷できるので、探している文字列を見つけると、探している文字列が格納されているキー構造をすぐに確認できますか?

現在、私は単純なコードを使用しています。

            use Data::Dumper;
            ...
            print Dumper $var;

素晴らしい出力を得るための最良の構文または代替手段は何ですか?

4

4 に答える 4

24

I almost always set

$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;

with Data::Dumper. The first statement makes the output more compact and much more readable when your data structure is several levels deep. The second statement makes it easier to scan the output and quickly find the keys you are most interested in.

If the data structure contains binary data or embedded tabs/newlines, also consider

$Data::Dumper::Useqq = 1;

which will output a suitable readable representation for that data.

Much more in the perldoc.

于 2012-03-13T16:42:06.777 に答える
10

考えられる解決策の1つは、Data::Dumpの出力をPerltidyで実行するData::Dumper::Perltidyを使用することです。

#!/usr/bin/perl -w

use strict;
use Data::Dumper::Perltidy;

my $data = [{ title => 'This is a test header' },{ data_range =>
           [ 0, 0, 3, 9] },{ format     => 'bold' }];

print Dumper $data;

__END__

プリント:

$VAR1 = [
    { 'title'      => 'This is a test header' },
    { 'data_range' => [ 0, 0, 3, 9 ] },
    { 'format'     => 'bold' }
];

もう1つの方法は、Data::Dumpを使用することです。

于 2012-03-13T20:16:24.293 に答える
0
$Data::Dumper::Sortkeys = 1;

より信頼性の高い結果を得たい場合は、次にダンパーに従う必要があります。その機能を操作するために適切な言葉を入れてください。

于 2013-07-01T07:45:44.150 に答える
-1

これは質問に答えます。

my $WWW_Scripter_Plugin_JavaScript_JE = ${ $VAR1->[1]{156192192} };
my $JE_Object_String = ${ $WWW_Scripter_Plugin_JavaScript_JE->{pf}{String} };
my $JE_Object_Function = ${ $JE_Object_String->{props}{search} };
my $REF = ${ $JE_Object_Function->{global} };
my $HTML_DOM_Element_Img = $REF->{classes}{'HTML::DOM::Element::Img'};

また、カプセル化に違反します。Perlでそれを行うことができますが、公開されているWWW ::ScripterAPIを使用してデータを取得する方法を尋ねる必要があります。

于 2012-03-13T17:57:46.797 に答える