Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Dear Monks I have 2 strings in this way:
String1: "big business"
String2: "big movie companies"
What I want to generate is something like "big business and movie companies" which is the smart concatenation. If both strings has the same size and if the position of the common word is the same the problem is easier. There are issues when the position of the common token is not same. Any idea would be appreciated.
The example is very dummy but when the length and the positions are different, then the normal positioning cant be used.
for $i (0 .. $#p2) { #print "$p1[$i] vs $p2[$i]\n"; $mism_pos{$i} = 1 if ($p1[$i] +eq $p2[$i]); } #print sort keys %mism_pos,"\n"; if (keys %mism_pos) { for $i (0..$#p2) { if (defined $mism_pos{$i}) + { if (@new1 && @new2) { push @new,@new1,'a +nd',@new2,$p2[$i]; @new1=(); @new2=(); } else { push @new,$p2[$i]; } } else { push @new1,$p1[$i]; push @new2,$p2[$i]; } } }
This solution would work if the length and positions are the same. However, I get also this error: "Use of uninitialized value within @p1 in concatenation (.) or string" and I get this as answer: "big"

In reply to Concatenating strings with different length by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2015-11-29 19:11 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (752 votes), past polls