Solved

Hashf a hash of a hash of a hash

Posted on 2012-04-03
15
295 Views
Last Modified: 2012-06-27
Hi,
I need to write a code that sorts filenames under different environements.

The heirarchy is as shown below-
Environment
Plan (around 50 palns)
Chapter (over 300)
Milestone (1,2,3,4)
Platform (A,B)
Owner(around 30)
Filenames (over 10000)

There are several plans. And each plan has several chapters. A plan and chapter of the same name can be present in another environment.
Now each chapter has filenames with the details of their owner and the milestone and platforms they are related to. Despite having same names the chapters can and will have different content in different environment.
I need to access these filenames and print them out in the followwing format

Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=1 , env= if its not the default env display the other env here)
#print files relevant to milestone 1 under that plan under that chapter
filename1
filename2
filename3
filename4
(milestone=2 , env= if its not the default env display the other env here)
filename5
filename6
filename7
(milestone=3 , env= if its not the default env display the other env here)
filename8
(milestone=4 , env= if its not the default env display the other env here)
filename9
filename10
filename11
filename12
filename13
filename14

If a plan has multiple chapters, it should print out multiple similar output for all chapters.
And it shoul depict change in environement, owner or platform in the milestone brackets.

Btw i'm sorting the data in excel and accessing an excel file. So first i dump the data in excel sort it and then access it. So everything is in an order.

Any help would be appreciated.
thanks
0
Comment
Question by:erum87
  • 9
  • 6
15 Comments
 

Author Comment

by:erum87
Comment Utility
I need to create hashes of hashes for this. Something like $hash{$plan}{$chap}{$mlst}{$env}.....
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Do you have a question about creating $hash{$plan}{$chap}{$mlst}{$env}?
Is it not working the way you expect?
0
 

Author Comment

by:erum87
Comment Utility
Well i have issues with creating a hash, yes.
0
 

Author Comment

by:erum87
Comment Utility
And then also using it in foreach since it has so many layers to it
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
What issues are you having?
0
 

Author Comment

by:erum87
Comment Utility
lets start with creating a multilayer hash. Do i need to declare it. If yes then how do i make it loop through plan first and within that plan, all the chapters and within that chapter all the testnames as per wrt milestones and environments.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
foreach $plan ( keys %hash ){
     foreach $chap ( keys %{$hash{$plan}} ){
          foreach $mist ( keys %{$hash{$plan}{$chap}} ){
                 foreach $env ( keys %{$hash{$plan}{$chap}{$mlst}} ){
                        print "\$hash{$plan}{$chap}{$mlst}{$env} = $hash{$plan}{$chap}{$mlst}{$env}\n";
                }
          }
      }
}
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
You do not need to declare it.
0
 

Author Comment

by:erum87
Comment Utility
Thanks :)
Another doubt
i'm creating an array fro plan, chapter, milestone and then looping through it.
foreach $plan(@plan){
    foreach $chap(@chapter){
        foreach $mlst(@mlst){
                       
(Do i include the hashes here ? )
                      }
              }
}
0
 

Author Comment

by:erum87
Comment Utility
And why did you create a hash reference in the print statement ?
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
If you already have the keys in arrays, then you don't need to get them from the hash
0
 

Author Comment

by:erum87
Comment Utility
The reason i wanted to use hashes was tomake the keys unique, since there are multiple occurances of plan and chapters etc. So where do I declare it so that the hash can access it.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
I did not create a hash reference in the print statement, I quoted the $ so it would print literally instead of interpolating a variable
You may want to declare
  my %hash;
or
  our %hash;
especially if you are under
  use strict refs;
0
 

Author Comment

by:erum87
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 500 points for ozo's comment #37803998
Assisted answer: 0 points for erum87's comment #37803988

for the following reason:

helped me understand how to really access and lp thru layers of hashes :)
0
 

Author Comment

by:erum87
Comment Utility
want more solutions
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 197
Perl - Mawk 2 69
Strange perl issue 6 122
Perl Awk Need Help 3 94
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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

12 Experts available now in Live!

Get 1:1 Help Now