473,387 Members | 1,724 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,387 software developers and data experts.

use a list to extract out the data...

Hi,
I'm new to Perl... I have some questions to extract the data out.
I have two files. One is gene list, and the other is the whole data(having gene lists and other values).
I'd like to extract the informations of the input lists.

I tried... but the RESULT file is empty!! I don't know what's wrong...
Here is my code.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2.  
  3. open(Data,"data.txt");
  4. @all = <Data>;
  5. close(Data);
  6.  
  7. open(List,"list.txt");
  8. @list = <List>;
  9. close(List);
  10.  
  11. open(ANS,">result.txt");
  12.  
  13. for($j=0;$j<$#list;$j++){
  14.  
  15.     chomp($list[$j]);
  16.  
  17.                }
  18.  
  19. for($i=0;$i<$#all;$i++){
  20.  
  21.     @b=split("\t",$all[$i]);
  22.  
  23.    for($j=0;$j<$#list;$j++){
  24.  
  25.     if($b[0] eq $list[$j]){
  26.  
  27.         print ANS "$all[$i]"; 
  28.  
  29.                }
  30.          }
  31. }
  32.  
  33. close(ANS);






Thanks!!!
May 21 '10 #1
5 1730
toolic
70 Expert
Since you didn't show any input data, you must debug your own code. Follow the tips in the Perl Basic debugging checklist.

Specifically, you should check the success of each file open, then start adding print statements to your code.
May 22 '10 #2
Hi,
here are my file contents(.jpg).
i've tried use the debugging checklist;
however, it didn't show anything.
Attached Images
File Type: jpg test.jpg (16.9 KB, 125 views)
May 22 '10 #3
RonB
589 Expert Mod 512MB
You're using the wrong data structure. Instead of 2 arrays, you should use 1 hash.

Load data.txt into a hash where the gene is the key and the value is the related data.

Then loop over list.txt and check if the gene is a key in the hash. If it is, then output the data.
May 22 '10 #4
hi,
i'm really new to Perl. i can't really understand, but i have tried...
here is my code, please tell me where is the problem.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. open(Data,"<data.txt");
  4. my %all= <Data>;
  5. my ($key, $value);
  6.  
  7. open(List,"<list.txt");
  8. my %list = <List>;
  9.  
  10. open(ANS,">result.txt");
  11.  
  12. while($all{$key} eq %list) {
  13.  
  14.         print ANS "%all"; 
  15.  
  16.                }
  17.  
  18. close(Data);
  19. close(List);
  20. close(ANS);
  21.  
May 22 '10 #5
RonB
589 Expert Mod 512MB
It doesn't appear that you understand the basics, so you probably wouldn't understand my descriptions on what you're doing wrong.

You need to start by getting a good beginner level Perl book.

Learning Perl, Fifth Edition
http://oreilly.com/catalog/9780596520113
May 22 '10 #6

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

Similar topics

0
by: Ashok | last post by:
Hi, is it possible to extract data from a web based java applet in order to enter that data in mysql? for example, something that would let me extract the data shown in applet on...
8
by: nick | last post by:
Hi all can any one please tell me what is wrong in this code?? I'm new to deal with text files and extract data. i'm trying to look for data in a text file (3~4 pages) some lines start with a...
1
by: basyarie | last post by:
Hello All, I`d like to introduce myself. I`m basyarie, now is student of university. Nice to meet you all. I`m beginner in this discussion community. Just want to ask about VB6 for GPS...
2
by: missolsr | last post by:
hi, I am using jpcap to capture OLSR topology control (udp) packets. Does anyone know how to extract data (the way ethereal does it) from the olsr packet? There are methods to extract data...
4
by: bootzwiz | last post by:
Hi, I want to extract data between tags. For example i have following code <span class="t_t_12_b_b">Cast</span><span class="t_t_12_b">: <a href="/test/">Mel Gibb</a></span> I want to...
1
by: bibie | last post by:
How to extract data from mssql and then convert it to mysql using VB6.0. How to connect the mssql..I know a little bit of VB6.0 but only create an interface using STANDARD EXE. Someone told me to...
5
by: ElTipo | last post by:
Hello People, I made a data base with secure wizard to provide to users a PID and Passwords. I need to extract data from Crystal Reports 7 in this data base but Crystal Reports send me a message...
5
by: =?Utf-8?B?aWxy?= | last post by:
Hi This is probably fairly simple but I am newish at programming and was wondering if someone can give me some advice on handling the following. I have an array with a large number of elements...
2
by: someusernamehere | last post by:
Hey, I need to create an application wich extract data from a .csv text (delimited by commas), the problem is that I only need some relevant data, its posssible extract what I want (may be with...
1
by: veer | last post by:
Hi i am making a program in which i want to extract data from html file . Actually there are two dates on html file i want to extract these dates but the main probleum is that these dates are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.