data-dumper

Perl hash Data::Dumper

北慕城南 提交于 2019-12-05 01:56:14
In Perl I need to analyze a huge hash, so I print it into a file using Data::Dumper module. Because it is a huge file, it is very hard to read. Is it possible somehow to print Dumper output nicely, so when I will find a string that I am looking for, I will be able to see immediately key structure where the string I am looking for is stored? Currently I am using just a simple code: use Data::Dumper; ... print Dumper $var; What is the best syntax or alternative to get nice output? I almost always set $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; with Data::Dumper . The first statement

How do I control the variable names in Perl's Data::Dumper?

寵の児 提交于 2019-12-03 09:34:39
问题 I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my %foo = ( 'abc' => 1 ); print Dumper(\%foo); It outputs: $VAR1 = { 'abc' => 1 }; How do I make it output this instead? %foo = ( 'abc' => 1 ); 回答1: print Data::Dumper->Dump( [ \%foo ], [ qw(*foo) ] ); The extended syntax takes two arrayrefs: one of scalars to dump, and one of names to use. If the name is prefixed by * and the corresponding scalar is an arrayref or hashref, an array or hash assignment is

How do I control the variable names in Perl's Data::Dumper?

喜欢而已 提交于 2019-12-02 23:58:29
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my %foo = ( 'abc' => 1 ); print Dumper(\%foo); It outputs: $VAR1 = { 'abc' => 1 }; How do I make it output this instead? %foo = ( 'abc' => 1 ); print Data::Dumper->Dump( [ \%foo ], [ qw(*foo) ] ); The extended syntax takes two arrayrefs: one of scalars to dump, and one of names to use. If the name is prefixed by * and the corresponding scalar is an arrayref or hashref, an array or hash assignment is produced. In addition to ysth's answer, you can use Ovid's Data::Dumper::Names module. Michel use Data::Dumper;

Iterating through an array of hashes

冷暖自知 提交于 2019-12-02 19:54:18
问题 I have wrote the below routine, to iterate through hashes 0 - 7 and print out the value of a specific key in each. I need to grab the value of 'b4' in each hash. I would like to do away with the (0..7), with something smarter for when there are different numbers of hashes. For instance, sometimes there is only 2 or there may be 160. my $out = decode_json $client->responseContent(); #print "\nOutput is :\n\n" . Dumper $out; for my $slice (0..7) { my $out = $out->{data}[$slice]{b4}; print "

Querying multiple times in Oracle using perl returns only the first query

牧云@^-^@ 提交于 2019-12-02 13:16:36
Note: I have corrected the variable differences and it does print the query from the first set but it returns nothing from the second set. If I use the second set only it works. In the code below, I have some_array which is array of array the array contains text like name. So @some_array= ([sam, jon, july],[Mike, Han,Tommy],[angie, sita, lanny]); Now when I querying the list like 'sam jon july' first and 'mike han tommy' . Only the execute return the result from the first list others is undef. I don't know why any help will be appreciated. my $pointer; my $db = $db->prepare_cached(" begin

Iterating through an array of hashes

纵饮孤独 提交于 2019-12-02 07:40:27
I have wrote the below routine, to iterate through hashes 0 - 7 and print out the value of a specific key in each. I need to grab the value of 'b4' in each hash. I would like to do away with the (0..7), with something smarter for when there are different numbers of hashes. For instance, sometimes there is only 2 or there may be 160. my $out = decode_json $client->responseContent(); #print "\nOutput is :\n\n" . Dumper $out; for my $slice (0..7) { my $out = $out->{data}[$slice]{b4}; print " $out \n"; } The data is structured as such: DB<1> x $out 0 HASH(0x125fb5e0) 'data' => ARRAY(0x1260d760) 0

Using Dumper not triggering a failure

混江龙づ霸主 提交于 2019-12-01 00:22:37
when running code like this: use strict; print Dumper "something"; nothing is printed out and no error occurs during compile and runtime. Why does this happen? Why doesn't strict prevent this code from running? Why is there no error at runtime, even though Dumper is unknown? I know it produces a warning when those are explicitly enabled, but I'm interested why is this code considered "correct" in any way. One of the valid syntaxes for print is print FILEHANDLE LIST In your program Perl is treating Dumper as a filehandle glob. Running this code with warnings enabled will tell you: print() on