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

Re: Binary Searches on Sorted Text Files

by scrottie (Scribe)
on Mar 14, 2003 at 03:53 UTC ( [id://242944]=note: print w/replies, xml ) Need Help??


in reply to Binary Searches on Sorted Text Files

Okey, lower case code tags don't work. Noted. Lets try that again:
my $word = shift @ARGV; open my $fh, 'WikiWikiList'; sub flup { my $start = shift; my $stop = shift; my $mid = int(($start + $stop) / 2); return 0 if $start == $mid or $stop == $mid; seek $fh, $mid, 0; <$fh>; my $line = <$fh>; chomp $line; print "debug: $start -> $mid -> $stop cmp: ", ($word cmp $line), +" $word vs $line\n"; return flup($start, $mid) if(($word cmp $line) == -1); return flup($mid, $stop) if(($word cmp $line) == 1); return 1; } if(flup(0, -s $fh)) { print qq{\xb7 Other Wikis: <a href="http://c2.com/cgi/wiki?$word"> +$word on WikiWiki</a><br><br>\n}; }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

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

    No recent polls found