Solved

build hash of hashes of hashes ...

Posted on 2004-09-19
2
233 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now