blog20100901

2013/08/20 - プログラミング言語 Perl にまつわる etc. - Perl monger
参考 : perldoc, perldoc.jp, search.cpan.org, perldoc.perl.org ...
「 初めての Perl 第 6 版 」(オライリー・ジャパン発行 ISBN978-4-87311-567-2) 」
「 続・初めての Perl 改訂版 」(オライリー・ジャパン発行 ISBN4-87311-305-9) 」
「 Effective Perl 第 2 版 」(翔泳社発行 ISBN978-4-7981-3981-4) 」 ... etc,.

Perl Perl_5 翻訳

Perl モジュール Data::Dumper 00 [翻訳] (d021)

Perl モジュール Data::Dumper 00 [翻訳] (d021)

目次 - Perl Index



Theme



Perl について、復習を兼ねて断片的な情報を掲載して行く連載その d021 回。


Perl で、データ構造をダンプ / eval できる便利なモジュール「 Data::Dumper 」のドキュメントを確認する。


以下は Data::Dumper - CPAN を *自家用* に翻訳したものです。正確な情報はリンク先の公式ドキュメントを確認します。

 ・ NAME ( 名前 )
 ・ SYNOPSIS ( 書式 )
 ・ DESCRIPTION ( 説明 )
  ・ Methods
  ・ Functions
  ・ Configuration Variables or Methods
  ・ Exports
 ・ EXAMPLE ( 例 )
 ・ BUGS ( バグ )
  ・ NOTE
 ・ AUTHOR ( 著者 )
 ・ VERSION ( バージョン )
 ・ SEE ALSO ( 参照 )


NAME ( 名前 )



Data::Dumper - stringified perl data structures, suitable for both printing and eval


Data::Dumper - 文字列化した perl データ構造, 両方に適した 出力 と eval


SYNOPSIS ( 書式 )




use Data::Dumper;

# simple procedural interface
# シンプルな手続きのインターフェイス
print Dumper($foo,$bar);

# extended usage with names
# 拡張した用法 名前の
print Data::Dumper->Dump([$foo,$bar],[qw(foo *ary)]);

# configuration variables
# 設定 変数
{
local $Data::Dumper::Purity = 1;
eval Data::Dumper->Dumper([$foo,$bar],[qw(foo *ary)]);
}

# OO usage
# オブジェクト指向 用法
$d = Data::Dumper->new([$foo,$bar],[qw(foo *ary)]);
...
print $d->Dump;
...
$d->Purity(1)->Terse(1)->Deepcopy(1);
eval $d->Dump;




DESCRIPTION ( 説明 )



Given a list of scalars or reference variables, writes out their contents in perl syntax. The references can also be objects. The content of each variable is output in a single Perl statement. Handles self-referential structures correctly.


与えると スカラのリスト または リファレンス変数を, 書き出します その内容を perl 構文で. リファレンスは またできます オブジェクトに. 各変数の内容を 出力します 単一の Perl 文で. 取り扱います 自己参照の構造体を 正しく.

The return value can be evaled to get back an identical copy of the original reference structure. (Please do consider the security implications of eval'ing code from untrusted sources!)


戻り値は eval して取り戻すことができます 同一のコピーを オリジナルの リファレンス構造体を. ( 考慮して行ってください セキュリティへの影響を 評価するコードの 信頼できないソースからの ! )

Any references that are the same as one of those passed in will be named $VARn (where n is a numeric suffix), and other duplicate references to substructures within $VARn will be appropriately labeled using arrow notation. You can specify names for individual values to be dumped if you use the Dump() method, or you can change the default $VAR prefix to something else. See $Data::Dumper::Varname and $Data::Dumper::Terse below.


すべてのリファレンスは 渡されたものと同じ 名前 $VARn になります ( ここで n は 数値サフィックスです ), それと 他の複製したリファレンスは $VARn の構造体への 適切にラベルされます 利用して 矢印記法を. あなたは 名前を指定できます ダンプする個々の値の もし あなたが 利用するなら Dump() メソッドを, または あなたは変更できます デフォルトの $VAR プレフィクスを 他の何かに. 参照してください $Data::Dumper::Varname と $Data::Dumper::Terse を 以下の.

The default output of self-referential structures can be evaled, but the nested references to $VARn will be undefined, since a recursive structure cannot be constructed using one Perl statement. You should set the Purity flag to 1 to get additional statements that will correctly fill in these references. Moreover, if evaled when strictures are in effect, you need to ensure that any variables it accesses are previously declared.


デフォルトの出力は 自己参照の構造体の eval できます, しかし ネストされたリファレンスは $VARn への 未定義になります 再帰的な構造は 構築できないので ひとつの Perl 文で. あなたはセットする必要があります Purity フラグを 1 に 追加の文を取得するために 正しく埋めた これらのリファレンスを. さらに, もし eval するなら 実際に構造体を, あなたは確認する必要があります すべての変数を そのアクセスが 前もって宣言されているか.

In the extended usage form, the references to be dumped can be given user-specified names. If a name begins with a *, the output will describe the dereferenced type of the supplied reference for hashes and arrays, and coderefs. Output of names will be avoided where possible if the Terse flag is set.


拡張した利用形式では, ダンプしたリファレンスに 与えることができます ユーザ指定の名前を. もし名前が * で始まるなら、出力は記述します デリファレンスタイプを 供給されたリファレンス ハッシュと配列, それと コードレフのための. 名前の出力は 回避されます 可能であれば もし Terse フラグがセットされている場合.

In many cases, methods that are used to set the internal state of the object will return the object itself, so method calls can be conveniently chained together.


多くの場合, メソッドは セットに使用されます オブジェクトの内部状態を返すように オブジェクト自体が, またメソッド呼び出しは 便利に連鎖できます 一緒に.

Several styles of output are possible, all controlled by setting the Indent flag. See "Configuration Variables or Methods" below for details.


出力のいくつかのスタイルは 可能です, すべてのコントロールが 設定によって インデントフラグの. 参照してください "Configuration Variables or Methods" 以下の 詳細については.

Methods

 ・ PACKAGE->new(ARRAYREF [, ARRAYREF])

Returns a newly created Data::Dumper object. The first argument is an anonymous array of values to be dumped. The optional second argument is an anonymous array of names for the values. The names need not have a leading $ sign, and must be comprised of alphanumeric characters. You can begin a name with a * to specify that the dereferenced type must be dumped instead of the reference itself, for ARRAY and HASH references.


返します 新しく作成された Data::Dumper オブジェクトを. 最初の引数は 無名配列です ダンプされる値の. オプションの第 2 引数は 無名配列です 値の名前の. 名前は持っている必要はありません 先頭に $ 記号を, それと 構成されなければなりません 英数文字で. あなたは 名前を * で始めることができます 指定するために デリファレンスのタイプを ダンプする必要のある リファレンスそれ自体の代わりに, 配列とハッシュリファレンスのために.

The prefix specified by $Data::Dumper::Varname will be used with a numeric suffix if the name for a value is undefined.


プレフィクスは $Data::Dumper::Varname によって指定された 利用されます 数値のサフィックスで もし値の名前が 未定義の場合.

Data::Dumper will catalog all references encountered while dumping the values. Cross-references (in the form of names of substructures in perl syntax) will be inserted at all possible points, preserving any structural interdependencies in the original set of values. Structure traversal is depth-first, and proceeds in order from the first supplied value to the last.


Data::Dumper は カタログします すべてのリファレンスを ダンプ中に遭遇した 値の. 相互参照は ( サブ構造体の名前の形式で perl 構文の ) 挿入され すべての可能なポイントに, 維持します すべての構造的な相互依存 値のオリジナルセットで. 構造体の走査は 深さ優先です, それと 進みます 順序で 最初に供給された値から 最後の.

 ・ $OBJ->Dump or PACKAGE->Dump(ARRAYREF [, ARRAYREF])

Returns the stringified form of the values stored in the object (preserving the order in which they were supplied to new), subject to the configuration options below. In a list context, it returns a list of strings corresponding to the supplied values.


返します 文字列化した形式を 格納された値の オブジェクトに ( 維持します その順序を それらが供給された new に ), 構成オプションの対象は 以下. リストコンテキストでは, それは返します 文字列のリストを 対応する 供給された値に.

The second form, for convenience, simply calls the new method on its arguments before dumping the object immediately.


2 番目の形式は, 便宜上, シンプルに呼びます new メソッドを その引数で オブジェクトのダンプの前に すぐに.

 ・ $OBJ->Seen([HASHREF])

Queries or adds to the internal table of already encountered references. You must use Reset to explicitly clear the table if needed. Such references are not dumped; instead, their names are inserted wherever they are encountered subsequently. This is useful especially for properly dumping subroutine references.


照会または追加します 内部テーブルに すでに遭遇したリファレンスの. あなたは利用しなければなりません Reset を 明示的にテーブルをクリアするには 必要に応じて. このようなリファレンスはダンプされません; 代わりに, それらの名前は挿入されます それらが遭遇した場所に その後. これは有用です 特に 適切にダンプするために サブルーチンリファレンスを.

Expects an anonymous hash of name => value pairs. Same rules apply for names as in new. If no argument is supplied, will return the "seen" list of name => value pairs, in a list context. Otherwise, returns the object itself.


期待します 無名ハッシュを name => value ペアの. 同じルールが適用されます new の名前に. もし引数を供給しない場合は, 返します "seen" リストを name => value ペアの, リストコンテキストで. それ以外では 返します オブジェクト自体を.

 ・ $OBJ->Values([ARRAYREF])

Queries or replaces the internal array of values that will be dumped. When called without arguments, returns the values as a list. When called with a reference to an array of replacement values, returns the object itself. When called with any other type of argument, dies.


照会または置換します 内部配列を ダンプされる値の. 引数なしで呼ばれたときは, 値を返します リストとして. 配列リファレンスと呼ばれたときは 置換する値の, オブジェクト自身を返します. 任意の他のタイプと呼ばれたときは 引数の, die します.

 ・ $OBJ->Names([ARRAYREF])

Queries or replaces the internal array of user supplied names for the values that will be dumped. When called without arguments, returns the names. When called with an array of replacement names, returns the object itself. If the number of replacement names exceeds the number of values to be named, the excess names will not be used. If the number of replacement names falls short of the number of values to be named, the list of replacement names will be exhausted and remaining values will not be renamed. When called with any other type of argument, dies.


照会または置換します 内部配列を ユーザが供給した名前の ダンプされる値の. 引数無しで呼ばれたときは, 名前を返します. 置換名の配列と呼ばれたときは, オブジェクト自身を返します. 置換名の数が 超える場合 名付けられた値の数を, 超えた名前は利用されません. 置換名の数が 下回る場合, 名付けられた値の数を, 置換名のリストを使いきります それと 残りの値は リネームしません. 任意の他のタイプと呼ばれたときは 引数の, die します.

 ・ $OBJ->Reset

Clears the internal table of "seen" references and returns the object itself.


クリアします 内部テーブルを "seen" のリファレンスを それと 返します オブジェクト自身を.

Function

 ・ Dumper(LIST)

Returns the stringified form of the values in the list, subject to the configuration options below. The values will be named $VARn in the output, where n is a numeric suffix. Will return a list of strings in a list context.


返します 文字列化した形式を リストの値の, 構成オプションの対象は 以下. 値は名付けられます $VARn と 出力で, その時 n は数値サフィックスです. 文字列のリストを返します リストコンテキストで.

Configuration Variables or Methods

Several configuration variables can be used to control the kind of output generated when using the procedural interface. These variables are usually localized in a block so that other parts of the code are not affected by the change.


いくつかの構成変数は 利用できます コントロールに 手続きインターフェイスを利用して出力を生成するときの. これらの変数は 通常ローカライズされます ブロックで なので その他のコードのパートには 変更による影響はありません.

These variables determine the default state of the object created by calling the new method, but cannot be used to alter the state of the object thereafter. The equivalent method names should be used instead to query or set the internal state of the object.


これらの変数は決定します デフォルトの状態を 作成されたオブジェクトの 呼び出しによって new メソッドの, しかし 利用できません 変更には オブジェクトの状態の その後の. 同じメソッド名は 利用するべきです 代わりに 照会または 内部状態のセットに オブジェクトの.

The method forms return the object itself when called with arguments, so that they can be chained together nicely.


メソッド形式は 返します オブジェクト自身を 引数と呼び出されたとき, なので それらは 連鎖させることができます きちんと.

 ・ $Data::Dumper::Indent or $OBJ->Indent([NEWVAL])

Controls the style of indentation. It can be set to 0, 1, 2 or 3. Style 0 spews output without any newlines, indentation, or spaces between list items. It is the most compact format possible that can still be called valid perl. Style 1 outputs a readable form with newlines but no fancy indentation (each level in the structure is simply indented by a fixed amount of whitespace). Style 2 (the default) outputs a very readable form which takes into account the length of hash keys (so the hash value lines up). Style 3 is like style 2, but also annotates the elements of arrays with their index (but the comment is on its own line, so array output consumes twice the number of lines). Style 2 is the default.


制御します インデントのスタイルを. これは セットできます 0, 1, 2 または 3 に. スタイル 0 は 吐き出します なしで すべての改行, インデント, または リストアイテムの間のスペースを. これは最もコンパクトな形式です 可能な限り 呼び出せる 有効な perl で. スタイル 1 は 出力します 読み取れる形式で 改行とともに しかし ファンシーなインデントはなしです ( 構造体の各レベルは シンプルにインデントされます 空白の一定量で ). スタイル 2 ( デフォルト ) は出力します とても読みやすい形式で 配慮した ハッシュ keys の長さを ( それで ハッシュ value 並びます ). スタイル 3 は スタイル 2 のようなものです, しかし また 注釈を付けます 配列の要素に それらのインデクスと ( しかし コメントは その独自の行にあります, なので 配列の出力は 2 倍消費します 行数を). スタイル 2 がデフォルトです.

 ・ $Data::Dumper::Purity or $OBJ->Purity([NEWVAL])

Controls the degree to which the output can be evaled to recreate the supplied reference structures. Setting it to 1 will output additional perl statements that will correctly recreate nested references. The default is 0.


程度を制御します 出力を eval できる 供給されたリファレンス構造を再作成した. 設定すると それを 1 に 出力します 追加 perl 文を 正しく再作成して ネストしたリファレンスを. デフォルトは 0 です.

 ・ $Data::Dumper::Pad or $OBJ->Pad([NEWVAL])

Specifies the string that will be prefixed to every line of the output. Empty string by default.


指定します 文字列を プレフィクスされる 出力のすべての行に. デフォルトでは空文字列です.

 ・ $Data::Dumper::Varname or $OBJ->Varname([NEWVAL])

Contains the prefix to use for tagging variable names in the output. The default is "VAR".


含みます 利用するプレフィクスを 変数名のタグ付けのために 出力の. デフォルトは "VAR" です.

 ・ $Data::Dumper::Useqq or $OBJ->Useqq([NEWVAL])

When set, enables the use of double quotes for representing string values. Whitespace other than space will be represented as [\n\t\r], "unsafe" characters will be backslashed, and unprintable characters will be output as quoted octal integers. Since setting this variable imposes a performance penalty, the default is 0. Dump() will run slower if this flag is set, since the fast XSUB implementation doesn't support it yet.


セットしたとき, 可能にします ダブルクォートの利用を 文字列値を表すための. 空白は スペース以外の 表されます [\n\t\r] として, "unsage" 文字は バックスラッシュされ, それから 出力不可の文字は 出力されます クォートされた 8 進整数で. この変数の設定は パフォーマンスのペナルティを課すので, デフォルトは 0 です. Dump() の実行は遅くなります もしこのフラグをセットしているなら, 高速な XSUB の実装が まだそれをサポートしていないので.

 ・ $Data::Dumper::Terse or $OBJ->Terse([NEWVAL])

When set, Data::Dumper will emit single, non-self-referential values as atoms/terms rather than statements. This means that the $VARn names will be avoided where possible, but be advised that such output may not always be parseable by eval.


セットしたとき, Deta::Dumper は シングルで出します, 非自己参照値を atoms/terms で 文というよりは. これは意味します $VARn の名前を 可能であれば回避することを, しかし アドバイスします このような出力は 常に解析できないかもしれないことを eval で.

 ・ $Data::Dumper::Freezer or $OBJ->Freezer([NEWVAL])

Can be set to a method name, or to an empty string to disable the feature. Data::Dumper will invoke that method via the object before attempting to stringify it. This method can alter the contents of the object (if, for instance, it contains data allocated from C), and even rebless it in a different package. The client is responsible for making sure the specified method can be called via the object, and that the object ends up containing only perl data types after the method has been called. Defaults to an empty string.


セットできます メソッド名, または 機能を無効にするために空文字を. Data::Dumper は 呼び出します そのメソッドを オブジェクトを介して 文字列化を試みる前に それを. このメソッドは変更できます オブジェクトの内容を ( もし, 例えば, それが含む場合 割り当てられたデータを C から ) , それと 異なるパッケージの rebless さえも. クライアントは責任があります 確かめる 指定されたメソッドが オブジェクトを介して呼べることを, それと そのオブジェクトが 含んで終わるか perl データタイプだけを メソッドが呼び出された後で. デフォルトは空文字列です.

If an object does not support the method specified (determined using UNIVERSAL::can()) then the call will be skipped. If the method dies a warning will be generated.


もし オブジェクトがサポートしていない場合 指定したメソッドを ( UNIVERSAL::can() を利用して決定した ) コールはスキップされます. もしメソッドが die するなら 警告を生成します.

 ・ $Data::Dumper::Toaster or $OBJ->Toaster([NEWVAL])

Can be set to a method name, or to an empty string to disable the feature. Data::Dumper will emit a method call for any objects that are to be dumped using the syntax bless(DATA, CLASS)->METHOD(). Note that this means that the method specified will have to perform any modifications required on the object (like creating new state within it, and/or reblessing it in a different package) and then return it. The client is responsible for making sure the method can be called via the object, and that it returns a valid object. Defaults to an empty string.


セットできます メソッド名, または 機能を無効にするために空文字を. Deta::Dumper は 出します メソッドコールを すべてのオブジェクトのために ダンプされる 構文 bless(DATA, CLASS)->METHOD(). を利用して. 注意してください これは意味します 指定されたメソッドは 実行する必要があります すべての変更を オブジェクトで要求された ( 新しい状態の作成など その中で, それと/または それの再ブレス 異なるパッケージの ) それから それを返します. クライアントは責任があります 確かめる オブジェクトを介してメソッドを呼び出せるか, それと それが返すことを 有効なオブジェクトを. デフォルトは空文字列です.

 ・ $Data::Dumper::Deepcopy or $OBJ->Deepcopy([NEWVAL])

Can be set to a boolean value to enable deep copies of structures. Cross-referencing will then only be done when absolutely essential (i.e., to break reference cycles). Default is 0.


セットできます ブール値を 有効にする 構造体のディープコピーを. 相互参照は 必要不可欠なときだけ行います ( i.e, 循環参照を壊す ). デフォルトは 0 です.

 ・ $Data::Dumper::Quotekeys or $OBJ->Quotekeys([NEWVAL])

Can be set to a boolean value to control whether hash keys are quoted. A defined false value will avoid quoting hash keys when it looks like a simple string. Default is 1, which will always enclose hash keys in quotes.


セットできます ブール値を コントロールする ハッシュ keys をクォートするかどうか. 定義された 偽 の値は 避けます ハッシュ keys のクォーティングを それが単なる文字列に見えるとき. デフォルトは 1 で, 常に囲みます ハッシュ keys を クォートで.

 ・ $Data::Dumper::Bless or $OBJ->Bless([NEWVAL])

Can be set to a string that specifies an alternative to the bless builtin operator used to create objects. A function with the specified name should exist, and should accept the same arguments as the builtin. Default is bless.


セットできます 文字列を 指定する bless を代替する 組み込みの演算子を利用して オブジェクトを作成するための. ファンクションは 存在する名前で指定しなければなりません, それと 受け入れる必要があります 同じ引数を 組み込みとして. デフォルトは bless です.

 ・ $Data::Dumper::Pair or $OBJ->Pair([NEWVAL])

Can be set to a string that specifies the separator between hash keys and values. To dump nested hash, array and scalar values to JavaScript, use: $Data::Dumper::Pair = ' : ';. Implementing bless in JavaScript is left as an exercise for the reader. A function with the specified name exists, and accepts the same arguments as the builtin.


セットできます 文字列を 指定する セパレータを ハッシュ keys と values の間の. ダンプするには ネストしたハッシュ, 配列 それと スカラ値を JavaScript に, 利用します: $Data::Dumper::Pair = ':'; を. bless を実装するのは JavaScript で 残しておきます 課題として 読者のための. ファンクションは 存在する名前で指定した, それと 受け付けます 同じ引数を 組み込みと.

Default is: => .


デフォルトは: => です.

 ・ $Data::Dumper::Maxdepth or $OBJ->Maxdepth([NEWVAL])

Can be set to a positive integer that specifies the depth beyond which we don't venture into a structure. Has no effect when Data::Dumper::Purity is set. (Useful in debugger when we often don't want to see more than enough). Default is 0, which means there is no maximum depth.


セットできます 正の整数を 指定する 深さを それを超えると 私たちは 踏み込みません 構造に. 効果はありません Data::Dumper::Purity がセットされているときは. ( デバッガで便利です 私たちがしばしば見たいと思わない時の 余計に). デフォルトは 0 で, それは意味します それらは最大の深さがないことを.

 ・ $Data::Dumper::Maxrecurse or $OBJ->Maxrecurse([NEWVAL])

Can be set to a positive integer that specifies the depth beyond which recursion into a structure will throw an exception. This is intended as a security measure to prevent perl running out of stack space when dumping an excessively deep structure. Can be set to 0 to remove the limit. Default is 1000.


セットできます 正の整数を 指定する 深さを それを超えると 構造への再帰は 例外を投げます. これは意図されています セキュリティ対策として 防止するために perl スタックスペースの枯渇を ダンプするときに あまりに深い構造を. セットできます 0 に 制限の削除のために. デフォルトは 1000 です.

 ・ $Data::Dumper::Useperl or $OBJ->Useperl([NEWVAL])

Can be set to a boolean value which controls whether the pure Perl implementation of Data::Dumper is used. The Data::Dumper module is a dual implementation, with almost all functionality written in both pure Perl and also in XS ('C'). Since the XS version is much faster, it will always be used if possible. This option lets you override the default behavior, usually for testing purposes only. Default is 0, which means the XS implementation will be used if possible.


セットできます ブール値を コントロールする Data::Dumper のピュア Perl 実装を利用するかどうかを. Data::Dumper モジュールは二重の実装です, ほとんどすべての機能は書かれています 両方で ピュア Perl と また XS('C') で. XS バージョンがより早いので, それは常に利用されます もし可能なら.このオプションで あなたはオーバーライドできます デフォルトの動作を, 通常はテスト目的のためのみです. デフォルトは 0 で, それは意味します XS 実装を利用することを もし可能なら.

 ・ $Data::Dumper::Sortkeys or $OBJ->Sortkeys([NEWVAL])

Can be set to a boolean value to control whether hash keys are dumped in sorted order. A true value will cause the keys of all hashes to be dumped in Perl's default sort order. Can also be set to a subroutine reference which will be called for each hash that is dumped. In this case Data::Dumper will call the subroutine once for each hash, passing it the reference of the hash. The purpose of the subroutine is to return a reference to an array of the keys that will be dumped, in the order that they should be dumped. Using this feature, you can control both the order of the keys, and which keys are actually used. In other words, this subroutine acts as a filter by which you can exclude certain keys from being dumped. Default is 0, which means that hash keys are not sorted.


セットできます ブール値を コントロールする ハッシュ keys を ソートした順序でダンプするかどうかを. 真 の値は すべてのハッシュの keys を Perl のデフォルトのソート順でダンプすることになります. またセットできます 呼びだしたサブルーチンリファレンスを ダンプされた各ハッシュのために. この場合 Data::Dumper は呼び出します いちどサブルーチンを 各ハッシュのために, 渡して その ハッシュのリファレンスを. サブルーチンの目的は 返すことです ダンプされる keys の配列へのリファレンスを, それらは順番にダンプされなければなりません. この機能を利用すると, あなたはコントロールできます 両方を keys の順序, それと 実際に使用する keys. 言い換えれば, このサブルーチンは機能します フィルタとして あなたが除外することで 特定の keys を ダンプされてから. デフォルトは 0 で, それは意味します ハッシュ keys がソートされていないことを.

 ・ $Data::Dumper::Deparse or $OBJ->Deparse([NEWVAL])

Can be set to a boolean value to control whether code references are turned into perl source code. If set to a true value, B::Deparse will be used to get the source of the code reference. Using this option will force using the Perl implementation of the dumper, since the fast XSUB implementation doesn't support it.


セットできます ブール値を コントローする コードリファレンスが perl ソースコードになっているかどうかを. もし 真 の値をセットした場合は, B::Deparse が利用されます ソースを取得するために コードリファレンスの. このオプションを利用すると強制します ダンパーの Perl 実装の利用を, 高速な XSUB 実装はサポートしていないので それを.

Caution : use this option only if you know that your coderefs will be properly reconstructed by B::Deparse.


注意 : このオプションを利用します あなたが知っている場合のみ あなたのコードレフが 適切に 再構築されることを B::Deparse によって.

 ・ $Data::Dumper::Sparseseen or $OBJ->Sparseseen([NEWVAL])

By default, Data::Dumper builds up the "seen" hash of scalars that it has encountered during serialization. This is very expensive. This seen hash is necessary to support and even just detect circular references. It is exposed to the user via the Seen() call both for writing and reading.


デフォルトでは, Data::Dumper は構築します スカラの "seen" ハッシュで 遭遇した シリアライズ化の間に. これはとても高価です. この seen ハッシュは サポートに必要です 循環参照の検出だけでも. それはさらされます ユーザに Seen() の呼び出しを介して 書き込みと呼び出しの両方で.

If you, as a user, do not need explicit access to the "seen" hash, then you can set the Sparseseen option to allow Data::Dumper to eschew building the "seen" hash for scalars that are known not to possess more than one reference. This speeds up serialization considerably if you use the XS implementation.


もしあなたが, ユーザとして, 明示的なアクセスを必要としないなら "seen" ハッシュへの, その後 あなたはセットできます [Sparseseen] オプションを 可能にするために Data::Dumper が 構築するのを控えるために "seen" ハッシュを スカラのために 知られている 持たない 1 つ以上のリファレンスを.これは スピードアップします シリアライズ化を かなり もし あなたが利用するなら XS 実装を.

Note: If you turn on Sparseseen, then you must not rely on the content of the seen hash since its contents will be an implementation detail!


注意: もしあなたが Sparseseen をオンにした場合, その後 あなたは頼ってはいけません seen ハッシュの内容に その内容は 実装の詳細になるので !

Exports

Dumper


EXAMPLE ( 例 )



Run these code snippets to get a quick feel for the behavior of this module. When you are through with these examples, you may want to add or change the various configuration variables described above, to see their behavior. (See the testsuite in the Data::Dumper distribution for more examples.)


これらのコードスニペットを実行します 手早く得るために このモジュールの動作の感触を. これらの例をすませたら, あなたは 追加や変更してもよいでしょう 様々な構成変数を 上述の, 見るために それらの動作を. ( 参照してください Deta::Dumper ディストリビューションのテストスイートを 他の例については. )


use Data::Dumper;

package Foo;
sub new {bless {'a'=> 1, 'b'=> sub{return "foo"}}, $_[0]};

package Fuz; # a weird REF-REF-SCALAR object
sub new {bless \($_ = \ 'fu\'z'), $_[0]};

package main;
$foo = Foo->new;
$fuz = Fuz->new;
$boo = [ 1, [], "abcd", \*foo,
{1 => 'a', 023 => 'b', 0x45 => 'c'},
\\"p\q\'r", $foo, $fuz];

########
# simple usage
########

$bar = eval(Dumper($boo));
print($@) if $@;
print Dumper($boo), Dumper($bar); # pretty print (no array indices)

$Data::Dumper::Terse = 1; # don't output names where feasible
$Data::Dumper::Indent = 0; # turn off all pretty print
print Dumper($boo), "\n";

$Data::Dumper::Indent = 1; # mild pretty print
print Dumper($boo);

$Data::Dumper::Indent = 3; # pretty print with array indices
print Dumper($boo);

$Data::Dumper::Useqq = 1; # print strings is double quotes
print Dumpe($boo);

$Data::Dumper::Pair = " : "; # specify hash key/value separator
print Dumper($boo);

########
# recursive structures
########

@c = ('c');
$c = \@c;
$b = {};
$a = [1,$b,$c];
$b->{a} = $a;
$b->{b} = $a->[1];
$b->{c} = $a->[2];
print Data::Dumper->Dump([$a,$b,$c],[qw(a b c)]);

$Data::Dumper::Purity = 1; # fill in the holes for eval
print Data::Dumper->Dump([$a,$b],[qw(*a b)]); # print as @a
print Data::Dumper->Dump([$b,$a],[qw(*b a)]); # print as @b


$Data::Dumper::Deepcopy = 1; # avoid cross-refs
print Data::Dumper->Dump([$b,$a],[qw(*b a)]);

$Data::Dumper::Purity = 0; # avoid cross-refs
print Data::Dumper->Dump([$b,$a],[qw(*b a)]);

########
# deep structures
########

$a = "pearl";
$b = [ $a ];
$c = { 'b' => $b };
$d = [ $c ];
$e = { 'd' => $d };
$f = { 'e' => $e };
print Data::Dumper->Dump([$f],[qw(f)]);

$Data::Dumper::Maxdepth = 3; # no deeper than 3 refs down
print Data::Dumper->Dump([$f],[qw(f)]);

########
# object-oriented usage
########

$d = Data::Dumper->new([$a,$b],[qw(a b)]);
$d->Seen({'*c' => $c}); # stash a ref without printing it
$d->Indent(3);
print $d->Dump;
$d->Reset->Purity(0); # empty the seen cache
print join "----\n", $d->Dump;

########
# persistence
########

package Foo;
sub new { bless{state => 'awake'}, shift}
sub Freeze {
my $s = shift;
print STDERR "preparing to sleep\n";
$s->{state} = 'asleep';
return bless $s, 'Foo::ZZZ';
}

package Foo::ZZZ;
sub Thaw {
my $s = shift;
print STDERR "waking up\n";
$s->{state} = "awake";
return bless $s, 'Foo';
}

package main;
use Data::Dumper;
$a = Foo->new;
$b = Data::Dumper->new([$a],['c']);
$b->Freezer('Freeze');
$b->Toaster('Thaw');
$c = $b->Dump;
print $c;
$d = eval $c;
print Data::Dumper->Dump([$d],['d']);

########
# symbol substitution (useful for recreating CODE refs)
########

sub foo { print "foo speaking\n" }
*other = \&foo;
$bar = [ \&other ];
$d = Data::Dumper->new([\&other,$bar],['*other','bar']);
$d->Seen({'*foo' => \&foo});
print $d->Dump;

########
# sorting and filtering hash keys
########

$Data::Dumper::Sortkeys = \&my_filter;
my $foo = { map{ (ord, "$_$_$_") } 'I'..'Q' };
my $bar = { %$foo };
my $baz = { reverse %$foo };
print Dumper [ $foo,$bar,$baz ];

sub my_filter {
my ($hash) = @_;
# return an array ref containing the hash keys to dump
# in the order that you want them to be dumped
retunr [
# Sort the keys of %$foo in reverse numeric order
$hash eq $foo ? (sort{$b <=> $a} keys %$hash) :
# Only dump the odd number keys of %$bar
$hash eq $bar ? (grep{$_ % 2} keys %$hash) :
# Sort keys in default order for all other hashes
(sort keys %$hash)
];
}



BUGS ( バグ )



Due to limitations of Perl subroutine call semantics, you cannot pass an array or hash. Prepend it with a \ to pass its reference instead. This will be remedied in time, now that Perl has subroutine prototypes. For now, you need to use the extended usage form, and prepend the name with a * to output it as a hash or array.


Perl サブルーチン呼び出しのセマンティクスの制限を原因として, あなたは渡すことができません 配列またはハッシュを. その先頭に追加します \ を 渡す リファレンスの代わりに. これは 修正されます そのうち, 今 Perl はサブルーチンプロトタイプをもっています. 今のところ, あなたは 利用する必要があります 拡張された利用形式を, それと 名前の先頭に追加します * を 出力に ハッシュまたは配列としての.

Data::Dumper cheats with CODE references. If a code reference is encountered in the structure being processed (and if you haven't set the Deparse flag), an anonymous subroutine that contains the string '"DUMMY"' will be inserted in its place, and a warning will be printed if Purity is set. You can eval the result, but bear in mind that the anonymous sub that gets created is just a placeholder. Someday, perl will have a switch to cache-on-demand the string representation of a compiled piece of code, I hope. If you have prior knowledge of all the code refs that your data structures are likely to have, you can use the Seen method to pre-seed the internal reference table and make the dumped output point to them, instead. See "EXAMPLES" above.


Data::Dumper はチートします CODE リファレンスを. もし コードリファレンスに遭遇した場合 構造を処理中に ( それと もしあなたがセットしていない場合 Deparse フラグを ), 無名サブルーチンを 文字列 "DUMMY" を含む 挿入します その場所に, それと 警告が表示されます もし Purity がセットされている場合. あなたは eval できます 結果を, しかし 心に留めます 無名 sub は 生成され取得した 単なるプレースホルダです. いつか, perl は切り替えます cache-on-demand に コードの一部をコンパイルした文字列表現を, 私は願います. もしあなたが予備知識を持っているなら すべてのコードレフの あなたのデータ構造が持っているかもしれない, あなたは利用できます [Seen] メソッドを pre-seed ( 事前設定 ? ) に 内部リファレンステーブルと それらのダンプ出力ポイントの作成に, 代わりに. 参照してください "EXAMPLES" 上記の.

The Useqq and Deparse flags makes Dump() run slower, since the XSUB implementation does not support them.


Useqq と Deparse フラグは Dump() の実行を遅くします, XSUB 実装はサポートしていないので それらを.

SCALAR objects have the weirdest looking bless workaround.


SCALAR オブジェクトは持っています 奇妙に見える bless の回避策を.

Pure Perl version of Data::Dumper escapes UTF-8 strings correctly only in Perl 5.8.0 and later.


ピュア Perl バージョンは Data::Dumper の エスケープします UTF-8 文字列を 正しく Perl 5.8.0 と以降でのみ.

NOTE

Starting from Perl 5.8.1 different runs of Perl will have different ordering of hash keys. The change was done for greater security, see "Algorithmic Complexity Attacks" in perlsec. This means that different runs of Perl will have different Data::Dumper outputs if the data contains hashes. If you need to have identical Data::Dumper outputs from different runs of Perl, use the environment variable PERL_HASH_SEED, see "PERL_HASH_SEED" in perlrun. Using this restores the old (platform-specific) ordering: an even prettier solution might be to use the Sortkeys filter of Data::Dumper.


Perl 5.8.1 の異なる実行で開始すると Perl は異なる順序を持ちます ハッシュ keys の. 変更は 行われました 強化するために セキュリティの, 参照してください "Algorithmic Complexity Attacks" を perlsec の. これは意味します Perl の異なる実行は 異なる Data::Dumper の出力を持つことを もしデータが含む場合 ハッシュを. もしあなたが 持っている必要がある場合 同一の Data::Dumper の出力を Perl の異なる実行からの, 利用します 環境変数 PERL_HASH_SEED を, 参照してください "PERL_HASH_SEED" を perlrun の. 使用します この復元を 古い ( プラットフォーム固有の ) 順序の: さらなる解決策は 利用するのが良いかもしれません Sortkeys のフィルタを Data::Dumper の.


AUTHOR ( 著者 )



Gurusamy Sarathy gsar@activestate.com

Copyright (c) 1996-2014 Gurusamy Sarathy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.



VERSION ( バージョン )



Version 2.154 (September 18 2014)



SEE ALSO ( 参照 )



perl(1)



NEXT



次回は、上記ドキュメントの「 EXAMPLES 」コードから「 simple usage 」を確認します。


参考情報は書籍「 続・初めての Perl 改訂版 」, 「 Effective Perl 第 2 版 」を中心に perldoc, Wikipedia および各 Web サイト。それと詳しい先輩。

目次 - Perl Index


























同じカテゴリー(Perl)の記事
 Perl mp2 翻訳 Web コンテンツ圧縮の FAQ (d228) (2023-10-11 23:49)
 Perl mp2 翻訳 既知のブラウザのバグの回避策をいくつか (d227) (2023-05-26 15:41)
 Perl mp2 翻訳 Perl と Apache でのキュートなトリック (d226) (2023-05-19 17:05)
 Perl mp2 翻訳 テンプレートシステムの選択 (d225) (2022-08-15 22:23)
 Perl mp2 翻訳 大規模 E コマースサイトの構築 (d224) (2022-06-15 20:43)
 Perl mp2 翻訳 チュートリアル (d223) (2022-06-15 20:42)
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。

Llama
リャマ
TI-DA
てぃーだブログ
プロフィール
セラ (perlackline)
セラ (perlackline)
QRコード
QRCODE
オーナーへメッセージ

PAGE TOP ▲