The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
StackedHash Perl program help pcjandyala Shell Programming and Scripting 2 06-11-2008 11:52 AM
Run shell program in perl s123.radha Shell Programming and Scripting 5 04-21-2008 09:39 AM
perl program question hankooknara Shell Programming and Scripting 4 07-05-2007 11:01 AM
Invoke perl program from Ksh mahalakshmi Shell Programming and Scripting 10 12-19-2006 08:46 AM
How to know the program 'perl' is installed ? zp523444 UNIX for Dummies Questions & Answers 3 12-13-2005 07:06 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
binnybio binnybio is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 4
an error in perl program

Hi

I am having a file with 243 lines..
The file format s given below

eg
P25787 hsa03050 1 P20618 hsa03050 1
P25786 hsa03050 1 P49721 hsa03050 1
P54132 hsa03440 1 Q13472 hsa03470 1
Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 hsa04530 hsa04910 hsa04930 3
O43463 hsa00310 1 Q92769 hsa04330 hsa04110 hsa05200 hsa05220 hsa05016 5

Here i have to seperate this file in to two.. ie if the 8 letter alphanumerical word s same in both the ids den it should be printed in one file

eg.

P25787 hsa03050 1 P20618 hsa03050 1
P25786 hsa03050 1 P49721 hsa03050 1
Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 hsa04530 hsa04910 hsa04930 3

The highlighted words shud be same


And the other one if the 8 letter alphanumerical word s different den it shud be printed in a file

eg

P54132 hsa03440 1 Q13472 hsa03470 1
O43463 hsa00310 1 Q92769 hsa04330 hsa04110 hsa05200 hsa05220 hsa05016 5

I wrote a perl code for this but its no working properly
the below given s the code

Code:
open(f1IN,"infile1.txt"); 
@id = <f1IN>; 
close(f1IN); 
 
open(f2IN,"infile2.txt"); 
@content = <f2IN>; 
close(f2IN); 
 
open(f3OUT,">same.txt"); 
open(f4OUT,">occurence1.txt");
open(f5OUT,">notsame.txt"); 
foreach my $id (@id) 
{ 
    chomp($id); 
    my $count = 0; 
    foreach my $line (@content)  
    { 
        chomp($line); 
        $line =~ s/(\t|\s{2,})/ /g; 
        while ( $line =~ /hsa$id/gi ) 
        { 
            $count ++; 
        } 
        @line = split(/ /,$line); 
        @count = grep /$id/,@line; 
        if ( scalar(@count) == 2 )  
        { 
            print f3OUT "$line\n";
}
        else
            {
                print f5OUT "$line\n";
            } 
         
    }     
    print f4OUT "$id --> $count\n" 
} 
close(f3OUT); 
close(f4OUT);
close(f5OUT);
The total number of lines in the input file s 243 so once i get two different files and the total of that 2 files shud come 243 but m getting sone 48,000 lines

pls reply me asap

Last edited by pludi; 2 Weeks Ago at 09:03 AM.. Reason: code tags, please...
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0