# See Data::Dumper module to get the default vaule of the # following module gobal variable. You can overwrite the # default value to user defined one.
print "Show perl hash, with pre-defined variable name\n "; print "and without maxdepth\n"; $Data::Dumper::Terse = 0; # default is 0 $Data::Dumper::Indent = 3; # default is 2 $Data::Dumper::Maxdepth = 0; # default is 0 my $variable_name = '*' . "my_info"; print Data::Dumper->Dump([\%people], [$variable_name]);
print "Show perl hash, without pre-defined variable name\n "; print "and with maxdepth is 1\n"; $Data::Dumper::Terse = 1; # default is 0 $Data::Dumper::Indent = 2; # default is 2 $Data::Dumper::Maxdepth = 1; # default is 0 $variable_name = '$' . "my_info"; print Data::Dumper->Dump([\%people], [$variable_name])
ray@localhost perl]$ perl data_dumper.pl Show perl hash, with pre-defined variable name and without maxdepth %my_info = ( 'food' => [ #0 'egg', #1 'apple' ], 'name' => 'ray', 'sex' => 'man', 'age' => 24 ); Show perl hash, without pre-defined variable name and with maxdepth is 1 { 'food' => 'ARRAY(0x91d68c4)', 'name' => 'ray', 'sex' => 'man', 'age' => 24 }