Jump to content

User:Jmax-/perlalg

From Wikipedia, the free encyclopedia
use warnings;
use strict;
use POSIX qw(floor);

my $res = search('talbot', 'Philippe Adjutor Talbot');
print "Found on $res\n";

sub search {
    my ($search_string, $page) = @_;
    my @revisions = get_revs($page); # revision data
    my $total_revisions = @revisions; # count
    my $revisions_left = $total_revisions - 1; # revisions left to check
    my $revision_number_to_check = floor($revisions_left / 2);
    
    while ($revisions_left > 1) {
        my $revision_to_check = $revisions->[$revision_number_to_check]; # revision datum
        $revisions_left = floor($revisions_left / 2);
        if (check_page($revision_to_check, $search_string)) {
            $revision_number_to_check -= floor($revisions_left / 2);
        } else {
            $revision_number_to_check += floor($revisions_left / 2);
        }
    }
    my $revision_to_check = $revisions->[$revision_number_to_check]; # revision datum
    if (check_page($revision_to_check, $search_string)) {
        return $revision_number_to_check;
    } else {
        return $revision_number_to_check + 1;
    }
}

sub check_page { # TODO
    # uses query.php to see if $page contains $search_string 
    # returns 1 if it does, 0 otherwise.
}

sub get_rev { # TODO
    # returns revisions for a specific page as a list of hashrefs.
}