Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
P is for Practical
 
PerlMonks  

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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2014-04-17 23:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (459 votes), past polls