1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Compare values in array

Discussion in 'Perl' started by terrylau, Aug 11, 2009.

  1. terrylau

    terrylau New Member

    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.
     
  2. shency

    shency New Member

    Two dimensional would be better!
     

Share This Page