in reply to Re: Perl Hash
in thread Perl Hash

Hi, Thanks a lot for the inputs. how can i ge this ouput for the same code. <DATA> Summary Detial_Summary EMC CHECK abcdefghi AZ_checker 1 44.32 EMC CHECK Grand_Total 1 44.32 Summary1 Detial_Summary1 EMC CHECK1 abcdefghi AZ_checker 1 44.59 EMC CHECK1 Grand_Total 1 44.59 </DATA>

Replies are listed 'Best First'.
Re^3: Perl Hash
by NetWallah (Canon) on Apr 17, 2013 at 05:44 UTC
    Use <code> tags, not <DATA>.

    To get the grand totals, add the following as the last line inside the WHILE loop:

    $h{$k1}{$k2}{+substr($k3,0,10) . " Grand Total"} += $val;
    This is a kludgy way to do it, but, given your sparse data definition, it does put out a grand total.

    A more robust implementation would require one more level of hashing - I leave that as an exercise for you to implement.

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs