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";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.