CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Compare values in array

 



terrylau
New User

Aug 11, 2009, 1:45 AM

Post #1 of 2 (384 views)
Compare values in array Can't Post

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.


KevinR
Veteran


Aug 11, 2009, 10:10 AM

Post #2 of 2 (374 views)
Re: [terrylau] Compare values in array [In reply to] Can't Post

this is obvious school or course work, so please post what code you have written so far. You could use a two dimensional array but it doesn't really sound necessary. Just process each line as you read the file, skip the line if it does not have 00A2 on the end, process it if it does to find the minority value.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives