Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: match with elements in array

by Marshall (Canon)
on May 18, 2010 at 22:49 UTC ( [id://840577]=note: print w/replies, xml ) Need Help??


in reply to match with elements in array

I like kennethk's idea. But since you asked about a hash way, I'll show a way...see below. This of course is a memory hog! But 14,000 hash keys wouldn't necessarily be considered "huge". The code to build the hash look up table is simple and then you would just query it for values of $vector. How efficient this thing has to be is of course a matter of your application. Something like this might be more appropriate if the "lane buckets" weren't contiguous or if there were multiple ranges associated with each lane.
#!/usr/bin/perl -w use strict; use Data::Dumper; my @lanes = ( [(200900..202543)], [(202544..204187)], [(204188..205831)], [(205832..207475)], [(207476..210119)], [(210120..211763)], [(211764..213407)], [(213408..215051)], ); my %hash; my $lane =1; foreach my $aref (@lanes) { @hash{@$aref} = ($lane) x @$aref; $lane++; } my $vector = 210121; print $hash{$vector}; #prints 6

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found