By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,542 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,542 IT Pros & Developers. It's quick & easy.

filehandle

P: 7
Hello people..I just wanted to know that can we store number of files in a filehandle ..if yes how could we do that???I did write a program but its just parsing result from the file which I'm giving at first position.
Thanx in advance !!
Sep 21 '08 #1
Share this Question
Share on Google+
7 Replies


KevinADC
Expert 2.5K+
P: 4,059
Post some code, your question is confusing.
Sep 21 '08 #2

P: 7
I have written this code.The output of this code should be total number of individual bases in both the files.
But the output is showing only total number of bases in first file i.e, pdb.txt.
I hope I made my question clear this time??Let me knw if u want some other information.Thanx in advance!!
Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. $/=undef;
  3.     $file1='C:\Users\documents\pdb.txt';
  4.     $file2='C:\Users\documents\pdb1.txt';
  5.     @files=($file1,$file2);
  6.     foreach $file(@files)
  7.     {
  8.     open(IN,$file) or "die error opening $file";
  9.     $data=<IN>;
  10.     $data1=reverse $data;
  11.     $data2=length $data1;
  12.     print"\nlength of sequence is $data2\n"; 
  13.     print"\nlength of sequence is $data1\n";
  14.     $a=($data=~tr/a/A/);
  15.     $t=($data=~tr/t/T/);
  16.     $g=($data=~tr/g/G/);
  17.     $c=($data=~tr/c/C/);
  18.  
  19.     $total=($a+$t+$g+$c);
  20.     }
  21.  
  22. print"The total number of adenine   are : $a\n";
  23. print"The total number of Thymine  are : $t\n";
  24. print"The total number of Guanine  are : $g\n";
  25. print"The total number of Cytosine are : $c\n";
  26. print"The total bases are $total";
  27.  
Sep 26 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
probably you need to change this line:

Expand|Select|Wrap|Line Numbers
  1. $total=($a+$t+$g+$c);
that overwrites the value of $total instead of summing all the values across all files:

try using "+=" instead of "=":

Expand|Select|Wrap|Line Numbers
  1. $total += ($a+$t+$g+$c);
Same for all of these if you want a sum across all files:

Expand|Select|Wrap|Line Numbers
  1. $a += ($data=~tr/a/A/);
  2. $t += ($data=~tr/t/T/);
  3. $g += ($data=~tr/g/G/);
  4. $c += ($data=~tr/c/C/);
  5.  
Sep 26 '08 #4

P: 7
yah...now its working...but not giving correct result... coz if I have 10 letters /bases in one of the file its showing 16...why??And how do I remove it??
Sep 26 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
Without seeing your data how do you expect me or anyone to know?
Sep 26 '08 #6

P: 7
I have two files having just lines of bases...like this
AGTGCCGTA and no other lines....
Sep 27 '08 #7

KevinADC
Expert 2.5K+
P: 4,059
I have two files having just lines of bases...like this
AGTGCCGTA and no other lines....
There is no way to debug the problem when you post one line of data. Post the real data you say gives incorrect results.
Sep 27 '08 #8

Post your reply

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