Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Searching text files

by johndageek (Hermit)
on Sep 15, 2006 at 18:49 UTC ( [id://573224]=note: print w/replies, xml ) Need Help??


in reply to Searching text files

Just a thought for fun, something like the following might work, of course it is stripped to show the general idea. create an array with 9,999,999 entries. create a bit mask for each area code. place the appropriate bitmask in the array entry corresponding to the phone number, this allows you to store 8 area codes per byte of data stored. of course all edit checks, warnings etc are stripped.
#!/usr/bin/perl open in,"987.txt" or die " could not open 987.txt as input"; # assign bit mask for this area code and pack it to binary $a = "00000001"; $b = pack('b8',$a); # load an array with the phone number less the area code as the subscr +ipt @arr; while (<in>){ chomp; $arr[$_]=$b; } # takes time to load about 10 seconds for all 10 million recs print "\n\narray loaded\n"; # response for lookup is sub-second while (true){ print "enter phone number: "; $pni = <>; chomp $pni; $pna = unpack('b8',$arr[$pni]); if (substr($pna,7,1) eq "1" ){ print "on file\n"; }else{ print "not on file\n"; } }

Enjoy!
Dageek

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found