Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Comparing Hash key with array

by thundergnat (Deacon)
on Feb 02, 2012 at 17:19 UTC ( #951496=note: print w/ replies, xml ) Need Help??


in reply to Comparing Hash key with array

It is kind of difficult to figure out exactly what you are trying to do. As far as I can tell, you are trying to do something like the following. You end up with an awful lot of duplicated information though.

If you showed an example of what your expected data structure looked like, it would be easier to help you.

Update: I see anonymonk already had similar advice...

use warnings; use strict; use Data::Dumper; my @totlines = map {chomp; [split /,/, $_]} <DATA>; #print Dumper \@totlines; my %hash = ( '_W9C2JJDCB' => [ '_W9C2JJDCB', '201200240', 'TEST: IGNORE', 'John Doe', 'Closed', 'HIP', 'email@email.com', 'email2@email.com', ], '_W9C2JJDCA' => [ '_W9C2JJDCA', '201200245', 'TEST: IGNORE', 'Jane Doe', 'Closed', 'HOP', 'email@imail.com', 'email2@imail.com', ], ); for my $line (@totlines) { my $key = $line->[0]; if ( defined $hash{$key} ){ push @{$hash{$key}}, @$line; } } print Dumper \%hash; __DATA__ _W9C2JJDCA,<P>This is the problem1.</P>,<P>This is res1</P> _W9C2JJDCA,<P>This is the problem2.</P>,<P>This is res2</P> _W9C2JJDCA,<P>This is the problem3.</P>,<P>This is res3</P> _W9C2JJDCB,<P>This is the problem1.</P>,<P>This is res1</P> _W9C2JJDCB,<P>This is the problem2.</P>,<P>This is res2</P> _W9C2JJDCB,<P>This is the problem3.</P>,<P>This is res3</P> _W9C2JJDCC,<P>This is the problem1.</P>,<P>This is res1</P> _W9C2JJDCC,<P>This is the problem2.</P>,<P>This is res2</P> _W9C2JJDCC,<P>This is the problem3.</P>,<P>This is res3</P>


Comment on Re: Comparing Hash key with array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-10-21 02:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls