Solved

build hash of hashes of hashes ...

Posted on 2004-09-19
2
235 Views
Last Modified: 2010-05-18
I have a file:

pkgName           uuName      tid      status      date1         date2
---------------         ---------      -----      --------      -----------      -----------  
PWCT001584        ve00208      NULL      Closed      20040805      20040805
PWCT001585        ve00208      NULL      Closed      20040805      20040805
PWJR001942        ve00208      NULL      Closed      20040806      20040806
PWJR002109        ve00208      NULL      Closed      20040618      20040618
PWXX001942        ve00208      NULL      Closed      20040806      20040806
PWXX002109        ve00208      NULL      Closed      20040618      20040618
PWCT001584        ve00208      NULL      Closed      20040805      20040805
PWCT001585        ve00208      NULL      Closed      20040805      20040805
PWJR001942        ve00208      NULL      Closed      20040806      20040806
PWJR002109        ve00208      NULL      Closed      20040618      20040618
PWXX001942        ve00208      NULL      Closed      20040806      20040806
PWXX002109        ve00208      NULL      Closed      20040618      20040618
PWXX002110        ve00208      NULL      Pending      20040618      20040618
PWCT001584        au00208      NULL      Closed      20040805      20040805
PWCT001585        au00208      NULL      Closed      20040805      20040805
PWJR001942        au00208      NULL      Closed      20040806      20040806
PWJR002109        au00208      NULL      Closed      20040618      20040618
PWXX001942        au00208      NULL      Closed      20040806      20040806
PWXX002109        au00208      NULL      Closed      20040618      20040618
PWXX002110        au00208      NULL      Pending      20040618      20040618

I need to build a hash containing counts for each uuName, for each group of
packages (where $pkgGroup = substr($pkgName, 0, 4)) for each status, ie.
$pkgCounts{'ve00208'}{'PWCT'}{'Closed'} should return 2
$pkgCounts{au00208}{'PWXX'}{'Pending'} should return 1 ...

This is done in a subroutine. $pkgCounts  is then returned to main for referencing
0
Comment
Question by:noodny
2 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 125 total points
ID: 12097134
Here's a script for you. It reads its input from the __DATA__ section. Its output looks like this:


$VAR1 = {
          'au00208' => {
                         'PWCT' => {
                                     'Closed' => 2
                                   },
                         'PWJR' => {
                                     'Closed' => 2
                                   },
                         'PWXX' => {
                                     'Pending' => 1,
                                     'Closed' => 2
                                   }
                       },
          've00208' => {
                         'PWCT' => {
                                     'Closed' => 4
                                   },
                         'PWJR' => {
                                     'Closed' => 4
                                   },
                         'PWXX' => {
                                     'Pending' => 1,
                                     'Closed' => 4
                                   }
                       }
        };




    #!/usr/bin/perl
    use Data::Dumper;

    $r = parse_file();

    print Dumper($r);


    sub parse_file {
        my %pkgCounts = ();

        ## skip first two lines;
        <DATA>, <DATA>;

        while(<DATA>) {

            my ($pkgName, $uuName, $tid, $status) = split ;
            $pkgCounts{$uuName}{substr($pkgName,0,4)}{$status}++;
        }

        \%pkgCounts;
    }

    __DATA__
    pkgName          uuName     tid     status     date1        date2
    ---------------        ---------     -----     --------     -----------     -----------  
    PWCT001584       ve00208     NULL     Closed     20040805     20040805
    PWCT001585       ve00208     NULL     Closed     20040805     20040805
    PWJR001942       ve00208     NULL     Closed     20040806     20040806
    PWJR002109       ve00208     NULL     Closed     20040618     20040618
    PWXX001942       ve00208     NULL     Closed     20040806     20040806
    PWXX002109       ve00208     NULL     Closed     20040618     20040618
    PWCT001584       ve00208     NULL     Closed     20040805     20040805
    PWCT001585       ve00208     NULL     Closed     20040805     20040805
    PWJR001942       ve00208     NULL     Closed     20040806     20040806
    PWJR002109       ve00208     NULL     Closed     20040618     20040618
    PWXX001942       ve00208     NULL     Closed     20040806     20040806
    PWXX002109       ve00208     NULL     Closed     20040618     20040618
    PWXX002110       ve00208     NULL     Pending     20040618     20040618
    PWCT001584       au00208     NULL     Closed     20040805     20040805
    PWCT001585       au00208     NULL     Closed     20040805     20040805
    PWJR001942       au00208     NULL     Closed     20040806     20040806
    PWJR002109       au00208     NULL     Closed     20040618     20040618
    PWXX001942       au00208     NULL     Closed     20040806     20040806
    PWXX002109       au00208     NULL     Closed     20040618     20040618
    PWXX002110       au00208     NULL     Pending     20040618     20040618
0
 

Author Comment

by:noodny
ID: 12097503
Thank u very much, kundura.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question