Solved

build hash of hashes of hashes ...

Posted on 2004-09-19
2
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

615 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