CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Suggest any Maximum Match Algorithm

 



tallamohan
New User

Jul 24, 2012, 5:32 AM

Post #1 of 3 (6288 views)
Suggest any Maximum Match Algorithm Can't Post

Here is the lines of string in a file

abxyz
abpqr
abmno
abcxyz
abcpqr
abcmno


I want the output as:-
ab+[xyz,pqr,mno]
abc+[xyz,pqr,mno]



Here is the real time data which should be in dictionary order:-

AduwoMxita
AduwoMxirA
AduwoMxileVMdi
AduwoMxile

I want the Output as:-

AduwoMxi+[ta,rA]
AduwoMxile[VMdi, ]

File the real time data in the attachment........


(This post was edited by tallamohan on Jul 24, 2012, 5:34 AM)


Chris Charley
User

Jul 30, 2012, 1:25 PM

Post #2 of 3 (5545 views)
Re: [tallamohan] Suggest any Maximum Match Algorithm [In reply to] Can't Post

Not a solution but may get you partway there. This is not a simple problem!

The output for this program is shown after the __END__ tag.


Code
##!/usr/bin/perl 
use strict;
use warnings;
use Inline::Files;

chomp(my $prev = <IN>);

while (my $current = <IN>) {
chomp $current;
($prev ^ $current) =~ /^\0+/;
my $index = $+[0];

printf "%-15s and %-15s have common prefix of %d\n", $prev,$current,$index || 0;
$prev = $current;
}

__IN__
AduwoMxita
AduwoMxirA
AduwoMxile
AduwoMxileVMdi
aa
abmno
abpqr
abxyz
abc
abcmno
abcpqr
abcxyz
__END__

C:\Old_Data\perlp>perl t9.pl
AduwoMxita and AduwoMxirA have common prefix of 8
AduwoMxirA and AduwoMxile have common prefix of 8
AduwoMxile and AduwoMxileVMdi have common prefix of 10
AduwoMxileVMdi and aa have common prefix of 0
aa and abmno have common prefix of 1
abmno and abpqr have common prefix of 2
abpqr and abxyz have common prefix of 2
abxyz and abc have common prefix of 2
abc and abcmno have common prefix of 3
abcmno and abcpqr have common prefix of 3
abcpqr and abcxyz have common prefix of 3



Chris Charley
User

Aug 24, 2012, 10:51 AM

Post #3 of 3 (4903 views)
Re: [tallamohan] Suggest any Maximum Match Algorithm [In reply to] Can't Post

What would be the maximum match when data is like below?


Quote
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa


Each match can be improved as the list goes on.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives