473,411 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

parsing problen in comparison of files.

Hi all,

I have two files resultset.csv and sws.lst. Content of two files:
resultset.csv has 5 columns(array index: 0,1,2,3,4)
sws.lst has 8 columns(array index: 0...7)

resultset.csv is small file containing 200 entries and sws.lst is big file containing around 10,000 entries.

what i am trying to do is match the resultset.csv(array index: 3 and 4) to the sws.lst(array index: 5,7) and if they match then a tab separated file will be written with all the column values from resultset.csv and sws.lst.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. open(FH,"<resultset.csv");
  5. open(TH,"<sws.lst");
  6. my (@temp1,@temp2,$pos1,$pos2,$acc1,$acc2);
  7.  
  8. while(<FH>)
  9. {
  10.     chomp $_;
  11.     @temp1=split(/,/,$_);
  12.     $pos1=$temp1[3];
  13.     $acc1=$temp1[4];
  14. }
  15. close(FH);
  16.  
  17. while(<TH>)
  18. {
  19.     chomp $_;
  20.     @temp2=split(/\t/,$_);
  21.     $pos2=$temp2[7];
  22.     $acc2=$temp2[5];
  23.     if($pos1 eq $pos2 && $acc1 eq $acc2)
  24.     {
  25.         print "Got it\n";
  26.     }
  27.     else
  28.     {
  29.         next;
  30.     }
  31. }
  32. close(TH);
  33.  
In the while loop when I gave only one condition then the code is running but when I tried to check both the condition with && it not giving results.

I also tried with making a hash with key and multiple values(as given in the perl cookbook) but didn't got results.

Any help and suggestions.

Kumar
Sep 21 '07 #1
6 1322
KevinADC
4,059 Expert 2GB
this is probably wrong:


Expand|Select|Wrap|Line Numbers
  1. while(<FH>)
  2. {
  3.     chomp $_;
  4.     @temp1=split(/,/,$_);
  5.     $pos1=$temp1[3];
  6.     $acc1=$temp1[4];
  7. }
  8. close(FH);
that reads through the entire file <FH> and sets $pos1 and $acc1 to whatever the last value was in the file (from the last line of the file I assume).
Sep 21 '07 #2
thanks for the reply...
then probably i should do the whole iteration in the while loop??

kumar
Sep 21 '07 #3
KevinADC
4,059 Expert 2GB
probably best to build a hash from the first file ( the shorter file) and then loop through the second file and see if the hash key exists and check the value, see if this works, should be close:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. open(FH,"<resultset.csv") or die "resultset.csv: $!";
  5. open(TH,"<sws.lst") or die "sws.lst: $!";
  6. my (@temp1,@temp2,$pos1,$pos2,$acc1,$acc2);
  7. my %hash;
  8. while(<FH>){
  9.     my ($k,$v) = (split(/,/,$_))[3,4];
  10.     $hash{$k} = $v;
  11. }
  12. close(FH);
  13.  
  14. while(<TH>){
  15.     chomp $_;
  16.     my($acc2, $pos2) = (split(/\t/,$_))[5,7];
  17.     if(exists $hash{$pos2} && $hash{$pos2} eq $acc2){
  18.         print "Got it\n";
  19.     }
  20.     else{
  21.         next;
  22.     }
  23. }
  24. close(TH); 
Sep 21 '07 #4
This code works only for one record.
Eg - For resultset.csv contains
resultset00,resultset01,resultset02,sws07,sws05
sws.lst contains
sws00 sws01 sws02 sws03 sws04 sws05 sws06 sws07
This will work fine, but for multiple records it does not work.
Seems to be problem in while loop or split fuction or may be the files resultset.csv and sws.lst does not contain valid data.
Please suggest
Sep 27 '07 #5
KevinADC
4,059 Expert 2GB
I would need to see some of the real data to help you further.
Sep 27 '07 #6
numberwhun
3,509 Expert Mod 2GB
This code works only for one record.
Eg - For resultset.csv contains
resultset00,resultset01,resultset02,sws07,sws05
sws.lst contains
sws00 sws01 sws02 sws03 sws04 sws05 sws06 sws07
This will work fine, but for multiple records it does not work.
Seems to be problem in while loop or split fuction or may be the files resultset.csv and sws.lst does not contain valid data.
Please suggest
I believe that after you posted this to the forum you clicked on the link that says "Report". Please do not do that. That link is to only be used to report posts that are offensive or against TSDN policies so that the Moderators are aware and can take care of it.

Once you post your message, that is all you need to do for someone to be able to know about it.

Regards,

Jeff
Sep 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS...
5
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS...
2
by: Justin Fancy | last post by:
Hi Everyone, I am creating a vb.net application, and i'm almost done. Except for one problem. I need to be able to change this output: C:\Documents and Settings\fancyj\My Documents\Visual...
7
by: Alan | last post by:
Hi. I have programmed in C++ before, but I`m a couple of years out of practice. I am seeking some advice on getting started on a quickie project. . . . I have to read a 54MB text file and do a...
3
by: =?Utf-8?B?TWljaGFlbCBIYWJlcmljaHRlcg==?= | last post by:
Hallo, I have a problem with a MissingManifestResourceException. I'm trying by days without finding any solution. Shortly the context: I have a .Net application (APPL_1), which does the...
1
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against...
0
by: HalfCoded | last post by:
hi everyone, I am kind of stuck and therefore would really appreciate some clues: I actually have to run a script which has to compare two elements from two different files which are a blast...
40
by: Phlip | last post by:
Scott Lurndal wrote: Would it also cause a problem if your file descriptors go "around the horn", and exceed some platform-specific limit, such as 0x80000000? They would "go negative" when...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.