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: Intermediate:
format

 



aec
New User

Feb 19, 2010, 4:08 AM

Post #1 of 3 (478 views)
format Can't Post

Hi, I have an input like this:

gene1 pos1 description1
gene2 pos2 description2a
gene2 pos2 description2b
gene2 pos2 description2c
gene3 pos3 description3
gene4 pos4 description4a
gene4 pos4 description4b

and I would like an output like this:

gene1 pos1 description1
gene2 pos2 description2a, description2b, description2c
gene3 pos3 description3
gene4 pos4 description4a, description4b

can anybody help me with the code?

#! /usr/local/bin/perl
use warnings;
use strict;

#program to print one gene per line with all the ontologies
my @aoa=0;

my $input= "genes";
open (FILE,'<', $input) or die "can not open $input file";
while (my $line=<FILE>){
my @array =split (/\t/, $line);
push (@aoa,[@array]);
my $i;
for ($i=1,$i<$#aoa,$i++){
if ($aoa[$i][0] eq $aoa[$i+1][0]){
push (@{$aoa[$i]}, $aoa[$i+1][2]);
}
else{
print "@{$aoa[$i]}\n";
}
}
}

Code


	

(This post was edited by aec on Feb 19, 2010, 8:09 AM)


toolic
User

Feb 19, 2010, 9:55 AM

Post #2 of 3 (465 views)
Re: [aec] format [In reply to] Can't Post

Fix your code tags.

Use a hash-of-arrays data structure instead of an array-of-arrays: http://perldoc.perl.org/perldsc.html#HASHES-OF-ARRAYS


7stud
Enthusiast

Feb 19, 2010, 11:24 PM

Post #3 of 3 (461 views)
Re: [aec] format [In reply to] Can't Post

Don't ever post code on a computer programming forum without using code tags. If you use code tags, you'll get some help. If you don't, you won't.


(This post was edited by 7stud on Feb 20, 2010, 12:02 AM)

 
 


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

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