perlquestion
Anonymous Monk
Dear Monks
I have 2 strings in this way:
</br>
String1: "big business"</br>
String2: "big movie companies"</br>
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.
</br>
The example is very dummy but when the length and the positions are different, then the normal positioning cant be used.
</br>
<code>
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,'and',@new2,$p2[$i];
@new1=();
@new2=();
}
else {
push @new,$p2[$i];
}
}
else {
push @new1,$p1[$i];
push @new2,$p2[$i];
}
}
}
</code>
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"
3