The following code should do what you want, provided that the tags always start at the same letter (from the beginning or end - see the DATA section for what I mean by that).

Instead of just creating the simple pairs you might be able to shift the player names characterwise against each other. Then you might get to a solution that doesn't contain the above stated restriction.

use strict; use warnings; use List::Util qw/reduce/; sub _extract { my @names = @_; my @pairs; # create all xor'd pairs for(my $i=0; $i<@names; $i++) { for (my $j=$i+1; $j<@names; $j++) { push @pairs, $names[$i] ^ $names[$j]; } } no warnings 'once'; my $or = reduce { $a | $b } @pairs; if ( $or =~ /\0+/ ) { my $index = $-[0]; my $length = $+[0] - $-[0]; return substr $names[0], $index, $length; } else { # match not successful, so return undef return; } } sub extract_tag { my @names = @_; my $tag; $tag = _extract(@names); # try matching with reversed @names # this finds common substrs at the end $tag = reverse _extract(map {scalar reverse $_} @names) unless defined $tag; return $tag; } my @names; local $, = ':'; local $\ = "\n"; while (<DATA>) { chomp; print(extract_tag(@names)), @names = (), next unless /\S/; push @names, $_; } print extract_tag(@names); __DATA__ jP|Azrael jP|Blade jP|Henry Jeff.ocr pr!me.ocr Lokren.ocr woRUTtan hiRUTfango biRUTff salTAGo blasTAGi RipTAGu

-- Hofmator


In reply to Re: String similarity extraction by Hofmator
in thread String similarity extraction by Braindead_One

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.