Hi Expert,

Mentioned earlier in my previous posts, that i am reading the data from text files and adding the common id's which comes under specific types

I am reading three files called file1, file2 and file3, the data in files are as....

Input file contains data as ...

file 1 A RACK 2 2 2 2 B RACK 2 2 2 2 A CACK 2 2 2 2 B CACK 2 2 2 2 file 2 A KACK 2 2 B KACK 2 2 file 3 E TACK 4 2 F TACK 4 2

code from perl monk by Kcott and i have modified

foreach my $file (@file_handles) { open FILE, "<$file" or die "file not exists\n"; while (chomp ( my ($id, $type, $val1, $val2, $val3, $val4) = split /\t +/, <FILE>) ) { $data{in}{$type}{$id}{val1} += $val1; $data{in}{$type}{$id}{val2} += $val2; $data{in}{$type}{$id}{val3} += $val3; $data{in}{$type}{$id}{val4} += $val4; $data{subtotal}{$type}{val1} += $val1; $data{subtotal}{$type}{val2} += $val2; $data{subtotal}{$type}{val3} += $val3; $data{subtotal}{$type}{val4} += $val4; $data{total}{val1} += $val1; $data{total}{val2} += $val2; $data{total}{val3} += $val3; $data{total}{val4} += $val4; } } close FILE; for my $type (sort keys %{$data{in}}) { print "$type\n"; for (sort keys %{$data{in}{$type}}) { print join("\t" => $_, @{$data{in}{$type}{$_}}{qw{val1 val2 va +l3 val4}})."\n"; } print join("\t" => 'Sub', @{$data{subtotal}{$type}}{qw{val1 val2 v +al3 val4}})."\n"; } print join("\t" => 'Tot', @{$data{total}}{qw{val1 val2 val3 val4}})."\ +n";

using the code which you mentioned in your previous reply, i got the below output

Output i got

A 2 2 2 2 Sub 2 2 2 2 KACK A 2 2 0 0 B 2 2 0 0 Sub 4 4 0 0 RACK A 2 2 2 2 B 2 2 2 2 Sub 4 4 4 4 TACK E 4 2 0 0 F 4 2 0 0 Sub 8 4 0 0 Tot 18 14 6 6

but i am trying to the output as below

A 2 2 2 2 Sub 2 2 2 2 KACK A 2 2 0 0 B 2 2 0 0 Sub 4 4 0 0 RACK A 2 2 2 2 B 2 2 2 2 Sub 4 4 4 4 Tot1 10 10 6 6 TACK E 4 2 0 0 F 4 2 0 0 Sub 8 4 0 0 Tot 18 14 6 6

Is posted correctlty now, please tell and thanks for your guidance and yes i am keen to learn, please guide me

Rgeards

Jen

In reply to Re^2: printing Hash references by Perlseeker_1
in thread printing Hash references by Perlseeker_1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.