Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

build hash of hashes of hashes ...

Posted on 2004-09-19
2
Medium Priority
?
241 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

670 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