sub insert_carrier_values { my $array_ref = shift; my $hash_ref = shift; for my $aref (@$array_ref) { #element 3 in the Hash Key if ( $aref->[3] > 0 ) { #Load the Array of Array with all the records from the query with the same element #3 if the Array does #not have something alreay there in postion 0 $hash_ref->{ $aref->[3] }[0] = [ $aref->[0], $aref->[1], $aref->[2], $aref->[4], $aref->[5], $aref->[6] ] unless defined( $rank{ $aref->[3] }->[0][0] ); # Same as above but now load postion # 1 if postion 0 if full $hash_ref->{ $aref->[3] }[1] = [ $aref->[0], $aref->[1], $aref->[2], $aref->[4], $aref->[5], $aref->[6] ] unless defined( $rank{ $aref->[3] }->[1][0] ); # Same as above but now load postion # 2 if postion 1 if full $hash_ref->{ $aref->[3] }[2] = [ $aref->[0], $aref->[1], $aref->[2], $aref->[4], $aref->[5], $aref->[6] ] unless defined( $rank{ $aref->[3] }->[2][0] ); # Same as above but now load postion # 3 if postion 2 if full $hash_ref->{ $aref->[3] }[3] = [ $aref->[0], $aref->[1], $aref->[2], $aref->[4], $aref->[5], $aref->[6] ] unless defined( $rank{ $aref->[3] }->[3][0] ); } } } # end sub insert_carrier_values