Solved

build hash of hashes of hashes ...

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

20 Experts available now in Live!

Get 1:1 Help Now