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 fields and get missing?

 



sabercats
Novice

Nov 16, 2012, 5:10 PM

Post #1 of 4 (1679 views)
Compare fields and get missing? Can't Post

Hi all,
I have a flatfile A.txt

Code
2012/11/13 20:06:11 |t112|Locations 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15|norway22 
2012/11/14 14:23:19 |t112|Locations 0, 1, 2, 3, 4, 5, 6, 7|NET24/full_111_ddr5_soq523_2X_FV.qt|norway|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15|norway10
2012/11/14 14:23:19 |a108|Locations 0, 1|NET24/full_111_ddr5_soq523_2X_FV.qt|germany|0,1,2,3|germany10
2012/11/14 16:23:19 |a108|Locations 0, 1,2,3|NET24/full_111_ddr5_soq523_2X_FV.qt|holland|0,1,2,3|holland10


How we do i get the result out put B.txt


Code
 
2012/11/13 20:06:11 |t112|Locations 12, 13, 14, 15|NET12/full_ddr3_2X_FV_4BD_1.qt|norway|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15|norway22
2012/11/14 14:23:19 |t112|Locations 0, 1, 2, 3, 4, 5, 6, 7|NET24/full_111_ddr5_soq523_2X_FV.qt|norway|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15|norway10
Currenttime|Available|Locations 8,9,10,11|Available|norway|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15|norway18
** norway18 is 10+8 from locations 8 is available, this line not in out put **
2012/11/14 14:23:19 |a108|Locations 0, 1|NET24/full_111_ddr5_soq523_2X_FV.qt|germany|0,1,2,3|germany10
Currenttime|Available|Locations 2,3|Available|germany|0,1,2,3|germany12
** germany12 is 10+2 from locations 2 is available, this line not in out put **
2012/11/14 16:23:19 |a108|Locations 0, 1,2,3|NET24/full_111_ddr5_soq523_2X_FV.qt|holland|0,1,2,3|holland10


Based on field#6 and compare field#3 with field#5 then write down what location are missing? like norway has location 0,1,2,3,4,5,6,7,12,13,14,15 and missed 8,9,10,11
Can we do that in perl?


wickedxter
User

Nov 16, 2012, 5:18 PM

Post #2 of 4 (1677 views)
Re: [sabercats] Compare fields and get missing? [In reply to] Can't Post

Im sure it is possible...


Laurent_R
Veteran / Moderator

Nov 17, 2012, 12:45 AM

Post #3 of 4 (1671 views)
Re: [wickedxter] Compare fields and get missing? [In reply to] Can't Post

Read the first line. Get the field with the country name and create an hash to store the values of field 3 (as keys of the hash) and an array to store the value of the last field.

Get the next line. If the country is the same, add the values of field 3 to the hash. Repeat so long as it is the same country.

When the country changes, iterate on the array values and check whether thay are in the hash. From there you can determina which values are missing.


sabercats
Novice

Nov 26, 2012, 11:20 AM

Post #4 of 4 (1510 views)
Re: [Laurent_R] Compare fields and get missing? [In reply to] Can't Post

I relly dont know how, can you all show me what code will you write? Thanks

 
 


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

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