Creating Hashes of Hashes of Array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating Hashes of Hashes of Array
# 1  
Old 03-06-2011
Creating Hashes of Hashes of Array

Hi folks,

I have a structure as mentioned below in a configuration file.

Code:
<Component>
Comp1:
         {
          item1:data,someUniqueAttribute;
          item2:data,someUniqueAttribute,
         }
Comp2:
         {
          item3:data,someUniqueAttribute;
          item4:data,someUniqueAttribute,
         }
</Component>

Example of the structure --

Code:
<CART>
Fruits:
    {
      apple: 10, "red";
          Clementine: 30, "orange";
          banana: 50, "yellow";
        }
    
Vegetables:
    {
     cucumber: 70, "green";
         potato: 80, "brown";
        }

<CART>

Firstly, I need to create a hash map of this structure in perl.
Then I need to use those uniqueAttributes (in this example the colours) to parse through another input file to find its match. Once the match is found I need to print its corresponding item & component on to the screen . (i.e in this example: if the colour "red" is matched in the input file, I need to print "apple" & "Fruits" to the screen) Smilie

Thanks & regards.

Last edited by radoulov; 03-06-2011 at 01:38 PM.. Reason: Code tags, please!
# 2  
Old 03-07-2011
This is what are you looking for ?
Code:
#!/usr/bin/perl
%fr_hash1=(red=>apple,
        orange=>Clementine,
        yellow=>banana);
%veg_hash1=(green=>cucumber,
                brown=>potato);
%fr_veg=(Fruit=>\%fr_hash1,
        Vegetable=>\%veg_hash1);

$colour=shift;

for (keys(%fr_veg)) {
print "${$fr_veg{$_}}{$colour} & $_ \n" if exists ${$fr_veg{$_}}{$colour};
}

invocation
Code:
perl fr_veg.pl red

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl hash of hashes anonymous array

Hello experts. I'm having problems with a snippet of code. I was hoping to get help/advice to correct. A file that this script parses has changed to the point where I can no longer use a scalar, it looks as though I need to create an array for a hash of hashes below. The first output of... (1 Reply)
Discussion started by: timj123
1 Replies

2. Cybersecurity

Whitelist, goodware, database of hashes

I have found this excellent site: NSRL Downloads (sorry if it was already mentioned) there are Solaris and Linux files there too. its all in a text file, over 11Gb large. (0 Replies)
Discussion started by: orange47
0 Replies

3. Shell Programming and Scripting

Perl : array of hashes help

Hi, I have array of hashes and each key has array like below. @array1 = ( { 'url' => , 'bill' => }, { 'url' => , 'bill' => }, { 'url' => , ... (0 Replies)
Discussion started by: ragilla
0 Replies

4. Shell Programming and Scripting

list of hashes

Hello everyone, I was wondering if someone can help me with this problem: @LoHashes = ({"a"=>1,"b"=>2,"c"=>3,"d"=>4}, {"a"=>5,"b"=>6,"c"=>7}); @LoHashes = create_list(\&LoHashes); sub create_list { foreach $hash(@LoHashes) { foreach (sort keys... (2 Replies)
Discussion started by: new bie
2 Replies

5. Shell Programming and Scripting

Hashes help in Perl

Hi, I am stuck at this problem where part of my code would store all the websites that has been accessed by a user. I pull these values from a log file. I want to create a HASH of HASHES ? (Please correct me if this is not the right approach) where I would store all the hits to website with... (4 Replies)
Discussion started by: Dabheeruz
4 Replies

6. UNIX for Dummies Questions & Answers

Name in hashes(####)???

Hey frens someone pls temme what i need to do so that after I logged into my unix terminal i should get my name written in hashes(i.e ###) Hope someone ll help me out.... (2 Replies)
Discussion started by: smarty86
2 Replies

7. Shell Programming and Scripting

Array split function & hashes

Hi, If this is the array that is being returned to me: How would I get the values for each of the 3 records? This works for 1 Record: foreach $item (@results) { ($id, $id2, $name, $date, $email) = split(/\|/, $item, 5); print "$name<br>"; } (2 Replies)
Discussion started by: novera
2 Replies

8. Shell Programming and Scripting

perl hashes question

hi guys im running into a problem here this is my script #!/usr/bin/perl use CGI qw(:standard); $header = "MIME-Version: 1.0\n"; $header .= "Content-type: text/html\n"; $header .= "\n"; #get the point parameter from nhl.html $Team = param("points"); print "$header"; open(INFILE,... (1 Reply)
Discussion started by: lucho_1
1 Replies

9. Shell Programming and Scripting

How To Sort Array of Hashes ??

Some one plz help me how to sort an array of hashes ..... for e.g i have an array as @AoH = ( { ques => 10, marks => 32, }, { ques => 32, marks => 22, }, { ques => 2, marks => 41, }, ); now i want to sort this array with increasing value of "ques" ..... plz... (3 Replies)
Discussion started by: coolguyshail
3 Replies

10. Shell Programming and Scripting

perl: hashes, whiles, and last

hello everyone, i am creating 2 hashes from 2 different files, then looking for the value of one in the value of the other to make a new file. for example: file1: DENV => Denver file2: H224-0A-12 => DENVER if Denver is found in DENVER (case insensitive), a new hash now contains H224-0A-12... (0 Replies)
Discussion started by: effigy
0 Replies
Login or Register to Ask a Question