Ben Maynard

NAME

String::Examine - String comparisions and offset checking

SYNOPSIS

   use String::Examine;

   my $str = String::Examine::new('string1' => 'foo', $string2 => 'bar');
   my $match = $str->compare();
   my $match2 = $str->nocase_compare();
   my $match3 = $str->regex_compare();
   my $match4 = $str->vector_compare();

   if($match || $match2 || $match3 || $match4)
   {
      my $offset = $str->str_pos();
   }

   $str->string2("new_string");
   $str->string1("new_string_also");

DESCRIPTION

This module does basic string comparision, string1 is always the primary that string2 is matched against there is 4 builtin comparisions, 'compare()' which just does a basic eq/ne compare, 'nocase_compare()' which converts to lowercase and does eq/ne match, 'regex_compare()' which is simply string matching using m//, 'vector_compare()' a slightly more unusual comparision, converts each character into vector and concatenates the converted vectors and does a '==' there is instances on some strings where this has found a failure that other compares failed to find, however, due to the nature it is the most expensive compare.

The final function is 'str_pos()' in the event that a string doesn't match this function can be called to find the position in the string2 where it failed, it is offset from 0, ie:

string1 = 'aaaaba'; string2 = 'aaaaaa';

str_pos() would return '4'.

FUNCTIONS

new

my $str = String::Examine::new();

You can pass the optional parameters 'string1', and 'string2' here.

string1

$str->string1("string");

If a value is pass string1 will be set to the value if not it will just return the currently set value.

string2

$str->string2("string");

If a value is pass string2 will be set to the value if not it will just return the currently set value.

compare

$str->compare();

Performs a basic eq compare on string1 and string2, string1 is always primary, returns 0 strings are equal or 1 if not

nocase_compare

$str->nocase_compare();

Exactly as compare() except it performs lc() first.

regex_compare

$str->regex_compare();

Performs the compare based on a regular expression using string1 =~ m/string2/ returns 0 if they are equal or 1 if not.

vector_compare

$str->vector_compare();

Converts the strings into 4bit vectors and performs a compare based on the concatenated output.

str_pos

$str->str_pos();

Returns the offset number of string2 at the point at which the 2 strings do not match, counts from 0.

EXPORT

None by default.

AUTHOR

Ben Maynard, <cpan@geekserv.com<gt> <http://www.webcentric-hosting.com<gt>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Ben Maynard, <cpan@geekserv.com<gt> <http://www.webcentric-hosting.com<gt>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.