Sponsored Content
Full Discussion: an error in perl program
Operating Systems Linux an error in perl program Post 302369223 by binnybio on Saturday 7th of November 2009 12:29:16 AM
Old 11-07-2009
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; 11-07-2009 at 09:03 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

StackedHash Perl program help

Hi guys, I need a favor from you guys. I am working on perl script which uses StackedHash( Thanks to Riccardo Murri) perl module and am almost there but unable to get it done. I really appriciate your help on this. Here are the details. thanks Purna Requirement: ========== Find out... (2 Replies)
Discussion started by: pcjandyala
2 Replies

2. Shell Programming and Scripting

perl program

I wish to write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted order by the file name. • By default, the program displays only file names. • By default, the program lists the files in the current directory. • The program must provide the... (2 Replies)
Discussion started by: livewire06
2 Replies

3. Shell Programming and Scripting

perl program

could i get any help with how to link this program together. i dont know what to put where the X's are print `flush`; thank(); #print thank header use Getopt::Std; # use declaration with the options function getopts("ld:") or usage() and exit; ... (3 Replies)
Discussion started by: livewire06
3 Replies

4. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

5. Programming

Perl program

Hi I am new to perl, i need to write a program to convert horizontal words to vertical eg: cat, dog, cow,.....(text file) this should be written as 1.cat 2.dog like this. can u pls help me to work out.. (4 Replies)
Discussion started by: nitha
4 Replies

6. Programming

Syntax error in perl program.

Hi, i am running this code but i am getting syntax error #!/usr/bin/perl use warnings; use strict; use XML::LibXML; use XML::LibXML::Reader; use Data::Dumper; my $file; open( $file, 'DTC_Specification_transformed.xml'); my $reader = XML::LibXML::Reader->new( IO => $file ) or die... (1 Reply)
Discussion started by: veerubiji
1 Replies

7. Shell Programming and Scripting

Help regarding a Perl Program

I want to traverse a durectory for a particular file. Situataion is like this. Path is ABC/a/c/g. it has around 100 folders in it. Search a directory which has word "*latest*" in its path. and then from the latest go through z/x/c to file final.html. In total, i want it to go through... (4 Replies)
Discussion started by: hemasid
4 Replies

8. Shell Programming and Scripting

awk program in perl

Hi All, I have an AWK code snippet which I want to use in Perl. How can I achieve the same thing in perl? Here I am searching for a pattern in a file and from that matching line, I am extracting the 3rd column value and storing it in a variable which I later on use this value in a if condition. ... (2 Replies)
Discussion started by: sanzee007
2 Replies

9. Shell Programming and Scripting

Perl program

can anyone help me out to write a code by connecting to the sql database and I need to print the list of tables present in the databse. any ideas please. (1 Reply)
Discussion started by: ramkumar15
1 Replies

10. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 04:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy