Ben Maynard


String::Examine - String comparisions and offset checking


   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();



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'.



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

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



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



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



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



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



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



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



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


None by default.


Ben Maynard, <<gt> <<gt>


Copyright (C) 2006 by Ben Maynard, <<gt> <<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.