I will spend some time to understand this part print for grep defined(), $s =~ /^$re2$/;

Maybe this will help:

#! perl -slw use strict; my @w = do{ local @ARGV = 'words.txt'; <> }; chomp @w; my $s = 'couldsomeonerecommendaworkingperlmoduletosplitconcatenatedwor +ds'; my @subset = grep{ $s =~ /$_/ } 'a', 'perl', @w; my $re1 = join '|', sort{ length( $b ) <=> length( $a ) }@subset; my $re2 = "($re1)?" x 20; my @found = $s =~ /^$re2$/; print join '|', @found; my @undefsRemoved = grep defined(), @found; print for @undefsRemoved;

Note: I've increase the number of repetitions from 11 to 20 to allow for sentences with more words. The side effect of that is that the unmatched captures now return undef, so If I just printed out @found, I get this:

c:\test>junk Use of uninitialized value $found[12] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[13] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[14] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[15] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[16] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[17] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[18] in join or string at C:\test\jun +k.pl line 15, <> line 178691. Use of uninitialized value $found[19] in join or string at C:\test\jun +k.pl line 15, <> line 178691. could|someone|recommend|aw|or|king|perl|module|to|split|concatenated|w +ords||||||||

So I use grep to remove any undefined values:

my @undefsRemoved = grep defined(), @found;
Actually it needs print "$_\n" for grep defined(), $s =~ /^$re2$/; to print line-wise.

If you look at the first line of the code I posted: #! perl -slw, the l in the -slw has the affect of adding "\n" to print statements automatically. Saves me having to type them all the time.

I can send you a link to the tool, but I am not sure it's a right way to do it through the forum.

Just post the link as text, or wrap it in brackets: [ link here ] to make it an active link.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


In reply to Re^5: Splitting compound (concatenated) words ) by BrowserUk
in thread Splitting compound (concatenated) words ) by vit

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.