Please help critcize and shorten my sub code

[email protected] (Richard Lee)
Newsgroups perl.beginners
Message-ID <[email protected]>
I dont know how to go through the array over and over again pending on 
my previous search so I ended up writing it like below which works.. but 
looks really really
inefficient..


sub dd_fact {
     my $routename = shift;
     my $routegroupid;
     my $trunkgroupid;
     my $carriername;
     my $carrier_active;
     my $carrierid;
     AHI: for (@dat) {
        if (exists $_->{outsideroute_group_m}{route_name}
             and $_->{outsideroute_group_m}{route_name} eq "$routename") {
             $routegroupid = $_->{outsideroute_group_m}{route_group_id};
             last AHI;
        }
     }

     EWF: for (@dat) {
        if (exists $_->{outsideroute_trunk_m}{route_group_id}
             and $_->{outsideroute_trunk_m}{route_group_id} eq 
"$routegroupid") {
             $trunkgroupid = $_->{outsideroute_trunk_m}{trunkgroup_id};
             last EWF;
        }
     }

     WWW: for (@dat) {
        if (exists $_->{outsideotrunkgroup_m}{trunkgroup_id}
             and $_->{outsideotrunkgroup_m}{trunkgroup_id} eq 
"$trunkgroupid") {
             $carrierid = $_->{outsideotrunkgroup_m}{carrier_id};
             last WWW;
        }
     }

     for (@dat) {
        if (exists $_->{outsidecarrier_m}{carrier_id}
             and $_->{outsidecarrier_m}{carrier_id} eq "$carrierid") {
             $carriername = $_->{outsidecarrier_m}{carrier_name};
             $carrier_active = live($_->{outsidecarrier_m}{active});
             return($trunkgroupid,$carriername,$carrier_active);
        }
     }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.