← Back to Perl Course | Chapter 8: Modules | Lesson 3 of 7

Data::Dumper का उपयोग

Data::Dumper किसी भी data structure को readable text में बदल देता है, जो debugging के लिए perfect है।

In this page:

  1. Data::Dumper

Data::Dumper

Data::Dumper Dumper function export करता है, जो एक structure को Perl code की तरह print करता है, nested data में references follow करते हुए। $Data::Dumper::Sortkeys = 1 set करना hash keys sort करता है ताकि output stable रहे, और $Data::Dumper::Indent layout control करता है। Dumper को \@array या \%hash जैसे references pass करें ताकि यह structure दिखाए, एक flattened list नहीं।

Note: $VAR1 = prefix और trailing semicolon हटाने के लिए $Data::Dumper::Terse = 1 set करें।

उदाहरण: Data::Dumper

perl
use strict;
use warnings;
use Data::Dumper;

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

my $data = {
    name   => "Ada",
    langs  => ["Perl", "C"],
    active => 1,
};
print Dumper($data);

$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 0;
print Dumper([1, "two", { three => 3 }]), "\n";

# Output:
# $VAR1 = {
#   'active' => 1,
#   'langs' => [
#     'Perl',
#     'C'
#   ],
#   'name' => 'Ada'
# };
# [1,'two',{'three' => 3}]
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक array या hash सीधे pass करना ताकि यह flatten हो जाए
  2. Sortkeys भूल जाना और हर run पर एक अलग key order पाना
  3. Dumper output को Perl versions के आर-पार एक stable data format की तरह इस्तेमाल करना
चैप्टर सारांश
  • Dumper structures को Perl code की तरह print करता है
  • इसे references pass करें
  • Sortkeys = 1 stable output देता है
  • Terse = 1 $VAR1 prefix हटाता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.