http://www.perlmonks.org?node_id=994837

supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How can I get the longest and all other common substrings from a set of strings?
by marto (Cardinal) on Sep 21, 2012 at 09:02 UTC

    Re read this and tell me what you don't understand or agree with. If you download code from somewhere, run it without attempting to understand it and get error messages, at least take the time to investigate these errors yourself. Stop copying modules manually (Where am I going wrong in the code for creating the first GUI using hello.pl?) and learn to install them properly.

    If you have no interest in learning to use the tools you have chosen (seemingly perl) to accomplish the task, select a different set of tools or change career.

Re: How can I get the longest and all other common substrings from a set of strings?
by Anonymous Monk on Sep 21, 2012 at 09:15 UTC

    I am a beginner in perl.

    This has been going on, post after post, for nine months. the honeymoon is over. No more walls of broken code. No more pretending to want to learn. We know effort when we see it, and we know when we're being used as a crutch.

Re: How can I get the longest and all other common substrings from a set of strings?
by prashantktyagi (Scribe) on Sep 21, 2012 at 08:17 UTC
    I would suggest you to learn perl first then go for writing programs.
    No one will here read your 100 lines of code and fix it.Please go through http://learn.perl.org first.
Re: How can I get the longest and all other common substrings from a set of strings?
by thundergnat (Deacon) on Sep 21, 2012 at 18:28 UTC

    Here you go.

    @s = qw(ABABC BABCA ABCBA); sub l{length@_[0]};for$i(0..$#s){$l=l$s[$i];for$s(0..$l-1){for$o(1..$l +-$s) {$t=substr$s[$i],$s,$o;if(!$i||exists$c{$t}){$c{$t}|=1<<$i}}}};print j +oin$/, 'Common subsequences:',@s,'-'x30,sort{l($b)<=>l$a}grep{$c{$_}==(1<<@s) +-1}keys%c;
    Common subsequences:
    ABABC
    BABCA
    ABCBA
    ------------------------------
    ABC
    BC
    BA
    AB
    C
    A
    B
    
    
A reply falls below the community's threshold of quality. You may see it by logging in.