How to retrieve three columns using perl

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 6
Reputation: annie_singh is an unknown quantity at this point 
Solved Threads: 0
annie_singh annie_singh is offline Offline
Newbie Poster

How to retrieve three columns using perl

 
0
  #1
Sep 30th, 2008
Hello,

I have a file with the data as shown below:

ATOM 2 CA ARG A 1 6.324 32.707 50.379
ATOM 13 CA THR A 2 5.197 32.618 46.826
ATOM 20 CA ASP A 3 4.020 36.132 46.259
ATOM 28 CA CYS A 4 7.131 38.210 45.919

I am a beginner in perl and i wrote a program to retrieve the last three columns and putting them in an array in order to calculate the distance

open (IN, "out.pl");
my $file = ' ';
while (<IN>) {
chomp($file);
my @array = /\d+\.\d+\s+\d+\.\d+\s+\d+\.\d+/
.....
am stuck.
for(#calculate distance){

}
}
close (IN);


I would like to know the script to match the three columns and putting them in an array and writng a for loop to calculate the distance between the four atoms given in the file.

Thank you,
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: How to retrieve three columns using perl

 
0
  #2
Sep 30th, 2008
  1. open (IN, "filename.pdb") or die "$!";
  2. while (my $line = <IN>) {
  3. chomp($line);
  4. my @array = (split(/\s+/,$line))[6,7,8];
  5. print "@array\n";
  6. }
  7. close (IN);

Look into perls math operators for the distance calculations. The above just shows an example of how to get the last three columns from a line with 9 columns of varying length data seperated by spaces.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: annie_singh is an unknown quantity at this point 
Solved Threads: 0
annie_singh annie_singh is offline Offline
Newbie Poster

Re: How to retrieve three columns using perl

 
0
  #3
Oct 1st, 2008
Thank you so much.. that really helped me solve the problem
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: How to retrieve three columns using perl

 
0
  #4
Oct 1st, 2008
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC