My file like this
(*CP*TP*TP*TP*TP*CP*TP*TP*TP*TP*AP*AP*AP*AP*AP*GP*TP*GP*GP
(*CP*TP*TP*TP*TP*CP*TP*TP*TP*TP*AP*AP*AP*AP*AP*GP*TP*GP*GP
(*CP*TP*TP*TP*TP*CP*TP*TP*TP*TP*AP*AP*AP*AP*AP*GP*TP*GP*GP
(*UP*CP*AP*GP*CP*CP*AP*CP*UP*UP*UP*UP*UP*AP*AP*AP*AP*GP*AP
(*UP*CP*AP*GP*CP*CP*AP*CP*UP*UP*UP*UP*UP*AP*AP*AP*AP*GP*AP
(*UP*CP*AP*GP*CP*CP*AP*CP*UP*UP*UP*UP*UP*AP*AP*AP*AP*GP*AP
values 290 MR1 1 1.000000 0.000000
values 290 MR2 1 0.000000 1.000000
values 290 MR3 1 0.000000 0.000000
values 290 MR1 2 -1.000000 0.000000
values 290 MR2 2 0.000000 -1.000000
values 290 MR3 2 0.000000 0.000000
values 290 MR1 3 -1.000000 0.000000
SEE FOR THE AUTHOR PROVIDED AND/OR PROGRAM GENERATED ASSEMBLY INFORMATION.
THIS ENTRY. THE REMARK MAY ALSO PROVIDE INFORMATION ON
BURIED SURFACE AREA.
350 COMPLETE MULTIMER REPRESENTING THE KNOWN
350 BIOLOGICALLY SIGNIFICANT OLIGOMERIZATION STATE OF THE
350 GENERATED BY APPLYING BIOMT TRANSFORMATIONS
350 GIVEN BELOW. BOTH NON-CRYSTALLOGRAPHIC AND
350 OPERATIONS ARE GIVEN.
350
350 BIOMOLECULE: 1
350 AUTHOR DETERMINED BIOLOGICAL UNIT
VALUES 944 CA SER A 124 19.929 15.508 41.001 1.00 27.16 C
VALUES 945 C SER A 124 18.528 15.865 41.525 1.00 27.86 C
VALUES 946 O SER A 124 18.305 16.949 42.074 1.00 29.52 O
VALUES 947 CB SER A 124 20.209 16.197 39.656 1.00 27.72 C
VALUES 948 OG SER A 124 19.168 16.143 38.688 1.00 29.83 O
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C
my script below
use warnings;
use strict;
print "Enter the filename >> ";
chomp(my $s = <>);
die "error openng file" unless (open('i',"$s"));
my @a=<i>;
my @grep = grep{s/^VALUES.*\w{3}\s\w//g} @a;
my @grep2 = grep{s/^values.*MR\d\s//g} @a;
my @x1;
my @y1;
my $y;
my $x;
foreach (@grep)
{
$x = (split)[1],$_;
$y = (split)[2],$_;
push (@x1,$x);
push (@y1,$y);
}
my @x2;
my @y2;
foreach (@grep2)
{
$x = (split)[1],$_;
$y = (split)[2],$_;
push (@x2,$x);
push (@y2,$y);
}
my @x;
my @y;
my @tot;
my $i; my $j;
for ($i=0 ; $i<@x1 ; $i++)
{
for ($j=0 ; $j<@x2 ; $j++)
{
my $m = $x1[$i] - $x2[$j];
my $v = $m/2;
push (@x , $v);
}
}
for ($i=0 ; $i<@y1 ; $i++)
{
for ($j=0 ; $j<@y2 ; $j++)
{
my $m = $y1[$i] - $y2[$j];
my $v = $m/2;
push (@y,$v);
}
}
for ($i=0 ; $i< scalar @x ; $i++)
{
my $total = $x[$i] + $y[$i];
print "$total\n";
push (@tot,$total);
}
#Below script i get confused
for(@grep)
{
my @mk = @tot <='17';
print "$_ \tWHICH ANSWER IS >> @mk\n";
}
Mathematical function used to 'values' and 'VALUES'. I get confused at how to print the values lessthan '17' which lines are print from the 'VALUES'. How i do it?
#I expect output is
VALUES 945 C SER A 124 18.528 15.865 41.525 1.00 27.86 C WHICH ANSWER IS >> 16.6965
VALUES 945 C SER A 124 18.528 15.865 41.525 1.00 27.86 C WHICH ANSWER IS >> 16.6965
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 15.756
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 15.756
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.256
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.256
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.756
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.256
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.756
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 15.187
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 15.187
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 15.687
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 16.187
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 16.187
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 15.687
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 16.187
And how avoid the 'Useless use of a variable in void context' error. in some lines
Your have yourself a little tied up here. Your main problem (and what took me so long to work out what it is you were aiming for) is that you create elements for @x
and @y
for every combination of @grep
and @grep2
instead of just pairing them up one for one
I take that back. On reflection, the biggest problem to understanding and fixing your code is your dreadful choice of variable names! I don't know what to call the data labelled VALUES
and values
so I have just used arrays @VALUES
and @values
, but you should rename them appropriately
I have come up with this program which does what I think you want. It produces only three output records which is far smaller than your example required output, but I think that output corresponds to a bigger input file? You should show the output you expected for the example input, otherwise we have no way of testing our solutions
I hope this helps
use strict;
use warnings;
use autodie;
print "Enter the filename: ";
chomp(my $filename = <>);
open my $in_fh, '<', $filename;
my (@VALUES, @values);
while (<$in_fh>) {
chomp;
if ( /^values/ ) {
push @values, [ $_, (split)[4,5] ];
}
elsif ( /^VALUES/ ) {
push @VALUES, [ $_, (split)[6,7] ];
}
}
for my $i (0 .. $#VALUES) {
my $total;
for my $j (1, 2) {
$total += ( $VALUES[$i][$j] - $values[$i][$j] ) / 2;
}
if ($total <= 17.0) {
printf "%s WHICH ANSWER IS >> %s\n", $VALUES[$i][0], $total;
}
}
output
VALUES 945 C SER A 124 18.528 15.865 41.525 1.00 27.86 C WHICH ANSWER IS >> 16.6965
VALUES 949 N LYS A 125 17.556 14.956 41.380 1.00 26.42 N WHICH ANSWER IS >> 16.256
VALUES 950 CA LYS A 125 16.202 15.172 41.869 1.00 26.36 C WHICH ANSWER IS >> 16.187