Marklitz has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I have to compare two string arrays. I have to check whether array1's element belong to array2 or not.
I have strings mixture of alphabets and numbers like:
Thanking you,
I have to compare two string arrays. I have to check whether array1's element belong to array2 or not.
I have strings mixture of alphabets and numbers like:
i tried byarray1 = {this1 this2 this11 this21 this23}; array2 = {h2this1 h3this2 h5this21 h6this23 h8this13}
Unfortunately, it prints as:for $i(0.. $#array1){ for $j(0.. $#array2){ if($array2[$j]=~ /$array1[$i]/){ print"$array1[$j] belongs to $array2[$i]"; last; }}}
instead of printing it as:this1 belongs to h2this1 this2 belongs to h3this2 this2 belongs to h5this21 this2 belongs to h6this23 this1 belongs to h8this13
I seek your advice.this1 belongs to h2this1 this2 belongs to h3this2 this21 belongs to h5this21 this23 belongs to h6this23 this1 belongs to h8this13
Thanking you,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Compare two arrays
by ELISHEVA (Prior) on Apr 02, 2009 at 10:47 UTC | |
Re: Compare two arrays
by almut (Canon) on Apr 02, 2009 at 10:52 UTC | |
Re: Compare two arrays
by johngg (Canon) on Apr 02, 2009 at 11:44 UTC | |
Re: Compare two arrays
by targetsmart (Curate) on Apr 02, 2009 at 11:56 UTC | |
by Russ (Deacon) on Apr 03, 2009 at 18:03 UTC | |
Re: Compare two arrays
by Bloodnok (Vicar) on Apr 02, 2009 at 11:26 UTC | |
by artist (Parson) on Apr 02, 2009 at 21:04 UTC | |
Re: Compare two arrays
by leslie (Pilgrim) on Apr 02, 2009 at 11:37 UTC |
Back to
Seekers of Perl Wisdom