Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Format a Dumper module output file.

by Arunbear (Parson)
on Oct 03, 2012 at 13:12 UTC ( #997052=note: print w/ replies, xml ) Need Help??


in reply to Format a Dumper module output file.

The output of Data::Dumper can be turned back into a Perl variable using eval (or do if it's in a file), so

#!/usr/bin/perl use strict; use warnings; my $file = shift or die 'no file given'; # parse output file my $var = do $file; my %words; foreach my $col (sort keys %$var) { my $hash = $var->{$col}; # collect values for each word while (my ($k, $v) = each %$hash) { push @{ $words{$k} }, $v; } } foreach my $word (sort keys %words) { printf "%s %s\n", $word, join(' ', @{ $words{$word} }); }
Then
% perl fmt.pl output.dump AIG 154 160 161 135 GID 18 27 18 17 TEA 235 224 224 214
where output.dump is just
$VAR1 = { '3' => { 'GID' => 18, 'AIG' => 161, 'TEA' => 224, }, '2' => { 'GID' => 27, 'AIG' => 160, 'TEA' => 224, }, '4' => { 'GID' => 17, 'AIG' => 135, 'TEA' => 214, }, '1' => { 'GID' => 18, 'AIG' => 154, 'TEA' => 235, } };


Comment on Re: Format a Dumper module output file.
Select or Download Code
Re^2: Format a Dumper module output file.
by oxydeepu (Novice) on Oct 03, 2012 at 13:30 UTC

    Thank you all.
    The response was amazing.
    Thanks Arun,this what i needed.

    Best,
    Deepak

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997052]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-04-16 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (424 votes), past polls