perl - How can I compare two arrays with alphanumeric elements? -


i have 2 arrays want compare

 @array1 = ( aaa, bbb, aaabbb, aaa23bbb, ddd555, 430hd9789);   @array2 = ( 34322hh2, jjfjr78, uuu7shv, ddd555, hjkdjroo); 

i have compare these 2 arrays , find duplicate , it.

conditions:

  1. length of each element in array can different. there no such fixed pattern.

  2. elements can numeric i.e. 334343, or char i.e. "somewordexample", or can alphanumeric i.e. wewe83493

  3. there can more such elements in array.

now know following comparison operators == , eq:

== comparing numbers

eq string comparison

how can compare alphanumeric values?

this code far

for (my $i = 0 ; $i <= $#array1 ; $i++ ) {   (my $j = 0 ; $j <= $#array2 ; $j++ ) {     if ( $array1[$i] == $arra2[$j] ) {       print "duplicate";     }   } } 

you manner indolent, , seem looking quick fix without caring whether understand solution. posts on stack overflow people other originator may have similar problem.

you should read perlfaq4. specifically:

  • perldoc -q intersection - "how compute difference of 2 arrays? how compute intersection of 2 arrays?"

  • perldoc -q contained - "how can tell whether element contained in list or array?"

  • perldoc -q duplicate - "how can remove duplicate elements list or array?"


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -