#!/usr/bin/perl

sub rabin_karp_unpack_C {
    my ( $T, $P ) = @_; # The text and the pattern.

    use integer;

    my ( $KRsum_P, $m ) = ( unpack( "%32C*", $P ), length($P) );

    my ( $i );
    my ( $last_i ) = length( $T ) - $m;

    for ( $i = 0; $i <= $last_i; $i++ ) {
        return $i
            if unpack( "%32C*", substr( $T, $i, $m ) ) == $KRsum_P and
               substr( $T, $i, $m ) eq $P;
    }

    return -1; # Mismatch.
}
