Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome or Safari browser. Firefox 10 (to be released soon) will also handle it.

Data::Dumper で print デバッグ

@tsucchi

自己紹介

まずはおわび

で、今回のテーマについて

バグ...つらいですよね

分かってしまえば簡単な事も、分かるまでは辛い

そんなバグに悩むプログラマの友...それが...

Data::Dumper

基本の使い方

use Data::Dumper;
...
warn Dumper($nanka_fukuzatsuna_data);
VAR1 = {
          'key2' => [
                      'value1',
                      'value2'
                    ],
          'key1' => 'some_value'
        };

デバッグ用途だとこんな感じ

use Data::Dumper; warn Dumper($nanka_fukuzatsuna_data);

長いメソッドのデバッグ

sub nagai_method {
...
   use Data::Dumper; warn Dumper($nanka_fukuzatsuna_data);
...
   use Data::Dumper; warn Dumper($nanka_fukuzatsuna_data);
...
}

2分探索

sub nagai_method {
...
   use Data::Dumper; warn "1: " . Dumper($nanka_fukuzatsuna_data);
...
   use Data::Dumper; warn "2: " . Dumper($nanka_fukuzatsuna_data);
...
   use Data::Dumper; warn "3: " . Dumper($nanka_fukuzatsuna_data);
...
   use Data::Dumper; warn "4: " . Dumper($nanka_fukuzatsuna_data);
...

ログに書く場合

use Data::Dumper; write_log Dumper("data_dayo: $nanka_fukuzatsuna_data");

問題の関数がどこから呼ばれてるか分からない

use Data::Dumper; warn Dumper("dokodaro: " . Dumper([caller()]) );

サブルーチンリファレンス使ってる場合

use Data::Dumper;
{
    local $Data::Dumper::Terse = 1;
    local $Data::Dumper::Indent = 1;
    local $Data::Dumper::Useqq = 1;
    local $Data::Dumper::Deparse = 1;
    local $Data::Dumper::Quotekeys = 0;
    local $Data::Dumper::Sortkeys = 1;
    warn Dumper($var);
}

print デバッグする際の前提

まとめ

※ 問☆題☆解☆決☆(画像はイメージです)

おしまい

Use a spacebar or arrow keys to navigate