Dear All
I have a code written in PERL. It is a working code for me.
But i want to rewrite it to make it a bit short and more scientific.
I have a similar task which is repeated again and again like in if else you can see the matching statements are also most similar except the number at the end of regexp. i.e 10, 11, 12, 13, 14, 18, 31 etc.
I also want to make it a bit more flexible so that it reads these numbers can be changed any time by a user input either by a text file or through command prompt and do not remains fixed as there are in this code.
I have a code written in PERL. It is a working code for me.
But i want to rewrite it to make it a bit short and more scientific.
I have a similar task which is repeated again and again like in if else you can see the matching statements are also most similar except the number at the end of regexp. i.e 10, 11, 12, 13, 14, 18, 31 etc.
I also want to make it a bit more flexible so that it reads these numbers can be changed any time by a user input either by a text file or through command prompt and do not remains fixed as there are in this code.
Code:
use strict;
#open the directory and than read all the files with *.txt
use Cwd;
my $dir = cwd;
opendir(DIR,"$dir") or die "$!";
my @all_pdb_files = grep {/\.txt$/} readdir DIR;
close DIR;
#reterive desired data from the txt file
foreach (@all_txt_files){
open (SP, "$_");
my $test;
my $test2;
my $test3;
my $test4;
my $test5;
my $test6;
my $test7;
my $test8;
my $test9;
my $test10;
my $test11;
my $test12;
my $test13;
my $test14;
my $test15;
my $test16;
my $test17;
my $test18;
my $test19;
my $test20;
my $test21;
my $test22;
my $test23;
my $test24;
my $test25;
my $test26;
my $test27;
my $test28;
my $test29;
my $test30;
while (<SP>){
#match txt Id in the file header
if ($_=~/^HEADER[\s\S]+(....)..............$/)
{
$test=$1;
#chomp $test;
#print "$test";
$test= "$test" . ".newtxt";
open (OUTPUT,">result/$test");
}
# open new out put files
if (/^HEADER[\s\S]+/)
{
$test21=$_;
print(OUTPUT "$test21");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+10\s/)
{
$test2=$_;
print(OUTPUT "$test2");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+11\s/)
{
$test3=$_;
print(OUTPUT "$test3");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+12\s/)
{
$test4=$_;
print(OUTPUT "$test4");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+13\s/)
{
$test5=$_;
print(OUTPUT "$test5");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+14\s/)
{
$test6=$_;
print(OUTPUT "$test6");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+18\s/)
{
$test7=$_;
print(OUTPUT "$test7");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+31\s/)
{
$test8=$_;
print(OUTPUT "$test8");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+33\s/)
{
$test9=$_;
print(OUTPUT "$test9");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+64\s/)
{
$test10=$_;
print(OUTPUT "$test10");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+80\s/)
{
$test11=$_;
print(OUTPUT "$test11");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+81\s/)
{
$test12=$_;
print(OUTPUT "$test12");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+82\s/)
{
$test13=$_;
print(OUTPUT "$test13");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+83\s/)
{
$test14=$_;
print(OUTPUT "$test14");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+84\s/)
{
$test15=$_;
print(OUTPUT "$test15");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+85\s/)
{
$test16=$_;
print(OUTPUT "$test16");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+86\s/)
{
$test17=$_;
print(OUTPUT "$test17");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+89\s/)
{
$test18=$_;
print(OUTPUT "$test18");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+129\s/)
{
$test19=$_;
print(OUTPUT "$test19");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+131\s/)
{
$test20=$_;
print(OUTPUT "$test20");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+132\s/)
{
$test22=$_;
print(OUTPUT "$test22");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+134\s/)
{
$test23=$_;
print(OUTPUT "$test23");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+144\s/)
{
$test25=$_;
print(OUTPUT "$test25");
}
if (/^ATOM\s+\S+\s+\S+\s+\S+\s+\S\s+145\s/)
{
$test26=$_;
print(OUTPUT "$test26");
}
}
}