Dnamonk3 has asked for the wisdom of the Perl Monks concerning the following question:
Sorting isn't helping either. For example in above arrays matching elements are: A2, A5 and G0.#!/bin/perl @array1 = ("A2","A5","C1","G0","T3","T4"); @array2 = ("A2","A3","A5","G1","G0","G4"); #@array1 = sort { $a <=> $b } @a1; #@array2 = sort { $a <=> $b } @a2; for($i = 0; $i <= $#array1; $i++){ while ($array1[$i] eq $array2[$i]){ print $array1[$i]."\n"; last; } }
But my code is only printing A5 ! I tried using forloop etc but doesn't work !
Thanks in advance for help.
Best
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Array compare not matching all elements
by 1nickt (Canon) on Oct 29, 2018 at 14:10 UTC | |
by Dnamonk3 (Novice) on Oct 29, 2018 at 14:31 UTC | |
Re: Array compare not matching all elements
by hippo (Archbishop) on Oct 29, 2018 at 14:11 UTC | |
by Dnamonk3 (Novice) on Oct 29, 2018 at 14:32 UTC | |
Re: Array compare not matching all elements
by roboticus (Chancellor) on Oct 29, 2018 at 14:50 UTC | |
Re: Array compare not matching all elements
by BillKSmith (Monsignor) on Oct 29, 2018 at 15:31 UTC | |
Re: Array compare not matching all elements
by dorko (Prior) on Oct 29, 2018 at 17:58 UTC | |
Re: Array compare not matching all elements
by cavac (Prior) on Oct 29, 2018 at 16:06 UTC |