Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Comparing Hash key with array

by Anonymous Monk
on Feb 02, 2012 at 16:28 UTC ( #951481=note: print w/ replies, xml ) Need Help??


in reply to Comparing Hash key with array

I appreiciate this is really hard to even explain correctly but I am hoping some will see some flaw in my logic in the "for key" loop?

It is a great thing you don't have to explain it ( How do I post a question effectively? ), simply post the correct representation of the data structure you're trying to achieve, I'll show you how to achieve it.


Comment on Re: Comparing Hash key with array
Re^2: Comparing Hash key with array
by packetstormer (Monk) on Feb 02, 2012 at 16:44 UTC
    OK - I will try and get a complete data dumper set of the date. In the meantime this seems to be my problem:
    foreach my $key(keys %ret) { my $value = $ret{$key}; my @arr = @$value; print "$key\n"; foreach my $u(@lines) { print "$key @$u\n"; } }
    The first FOREACH (if on it's own will print out the correct amount of keys in the hash.
    However, as soon as I add the second FOREACH (to enter the array) the keys get replicate the same amount of times the loop iterates.

      OK - I will try and get a complete data dumper set of the date.

      It isn't really necessary, simply type/copy/paste to make %hash (or %ret) look the way you want.

      In the meantime this seems to be my problem

      Thanks, but I knew this much from your original posting, I can't infer your intent -- you use == to compare strings, and you switched from %hash to %ret

Re^2: Comparing Hash key with array
by packetstormer (Monk) on Feb 02, 2012 at 17:21 UTC
    Here is the data in very simple form
    $VAR1 = { '_LFOGH4MI5' => [ '_LFOGH4MI5', '201200260', 'Software Extraction Util', 'Jane Smith', 'Closed', 'Database Query', 'email1@email.com', 'email2@email.com' ], '_W9E2B5DBZ' => [ '_W9E2B5DBZ', '201200261', 'TEST: Another test to test the testy thin +g', 'Mike Jones', 'Closed', 'HIP', 'email1@email.com', 'email2@email.com' ] }; $VAR1 = [ [ '_LFOGH4MI5', '<P>Where is the extraction utily for the console database +?.</P>', '<P>I uploaded it to our website for you to download.</P>' ], [ '_W9E2B5DBZ', '<P>Problem2</P>', '<P>Res2</P>' ], [ '_W9E2B5DBZ', '<P>Problem 1- teest</P>', '<P>Res1 - teest</P>' ], [ '_W9E2B5DBZ', '<P>Prob3</P>', '<P>res3</P>' ] ];

    So, I have a hash with the unique ID as it's key. In another part of the database is another table with problems/resolutions attached to the same unique ID. That is contained in the array (in array references). Each array has the unique ID in it first element.

    What I would like to do is start on that hash and take it's key. The run through the array and anywhere I get a match for the same ID push the rest of the array into the original value of the hash. In some cases, like above, there might be many arrays with the same ID (loads of problems/resolutions attached to the same case).

    I'd really appreciate any help, my head is set to burst!
    BTW, I have tried to lump the data together at the SQL end but datatype differences are stopping me grouping them there.

    EDIT: Hash should end up like:

    '_LFOGH4MI5' => [ '_LFOGH4MI5', '201200260', 'Software Extraction Util', 'Jane Smith', 'Closed', 'Database Query', 'email1@email.com', 'email2@email.com' '<P>Where is the extraction utily for the c +onsole database?.</P>', '<P>I uploaded it to our website for you to download.</P>' ], '_W9E2B5DBZ' => [ '_W9E2B5DBZ', '201200261', 'TEST: Another test to test the testy thin +g', 'Mike Jones', 'Closed', 'HIP', 'email1@email.com', 'email2@email.com' '<P>Problem2</P>', '<P>Res2</P>' '<P>Problem 1- teest</P>', '<P>Res1 - teest</P>' '<P>Prob3</P>', '<P>res3</P>' ] };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-07-12 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls