Now this works excellently as it tells me which service from my origin matches in my destination. However how can I also gain access to the associated data with each row in the query? For example, if I find that both queries have the same service, how can I then find the associate stops from the query relating to that service for each my origin and my destination? Do I have to make an array for each other variable in the queries too or a hash for each? Im not really an expert on hashes so any help and advice would be more than welcome. Thanksmy %ids; $origsql = qq{ SELECT route_number, stop_reference, depart_time FROM r +outes WHERE distance < 200...........}; #all SQL code not included he +re $sth = $dbh->prepare( $origsql ); $sth->execute(); $sth->bind_columns( undef, \$orig_service_id, \$orig_stop, $depart_ori +g); while ($sth->fetch()) { push(@orig_service_ids, $orig_service_id); } for my $id (@orig_service_ids) { $ids{$id} = 1; } # ... $destsql = qq{ SELECT route_number, stop_reference, depart_time FROM r +outes WHERE distance < 200...........}; #all SQL code not included he +re $sth = $dbh->prepare( $destsql ); $sth->execute(); $sth->bind_columns( undef, \$dest_service_id, \$dest_stop, $depart_des +t); while ($sth->fetch()) { push(@dest_service_ids, $dest_service_id); } for my $id (@dest_service_ids) { if (exists $ids{$id}) { print "ID $id exists in both origin and destination set\n"; } }
In reply to Keeping associated data after entering into a hash by Harch84
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |