Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Combining arrays of hashes

by ant9000 (Monk)
on Jul 09, 2003 at 09:39 UTC ( [id://272631]=note: print w/replies, xml ) Need Help??


in reply to Combining arrays of hashes

I'd build a temporary hash before array3:
%hash3 = map { $_->{year}.$->{month}.$_->{day}.$_->{hhmm}= $_ } @array1; for(@array2){ $k=$_->{year}.$->{month}.$_->{day}.$_->{hhmm}; if(!defined $tmp{$k}){ $hash3{$k}=$_; }else{ $hash3{$k}->{data2}=$_->{data2}; } } @array3=map { $hash3{$_} } sort keys %hash3; #or just @array3=values %hash3; #if you don't care about sorting

That should be pretty fast if you use map on the larger array (I assumed it is @array1). HTH!
(beware, the code is untested)
Update:
if(!defined $tmp{$k}){

should be
if(!defined $hash3{$k}){

Well, I'm learning by trial and error, it seems.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found