Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Compare values in array (http://www.go4expert.com/forums/compare-values-array-t18986/)

terrylau 11Aug2009 14:05

Compare values in array
 
row0 device1, device2, device3, device4, device5, device_label
row1 0000, 0000, 0000, 0000, 0000, 00A1
row2 0000, 2222, 0000, 1111, 0000, 00A2
row3 0000, 0000, 0000, 0000, 0000, 00A3
row4 0000, 0000, 0000, 0000, 0000, 00A1
row5 0000, 0000, 0000, 3333, 0000, 00A2
row6 0000, 0000, 0000, 0000, 0000, 00A3

Hi am a Perl newbie here... Need a Perl script to do this.

1. Scan all the fields from top to bottom and load into array. (Done)
2. Select the lines with the device_label 00A2 only.
3. Compare all the values within the lines, and select those with the different value from the majority value (in this case is 0000, could be other values).
4. Print out which fields that has the different value from the majority. In this case the output should be row2 device2, row2 device4 and row5 device4.

Which is better? Load all the values into a single array or a two-dimensional array for easier comparison?

I've managed to do step 1 but stuck on proceeding to the rest. Would appreciate advice and guidance here.

shency 26Aug2009 11:10

Re: Compare values in array
 
Two dimensional would be better!


All times are GMT +5.5. The time now is 15:23.