On Jun 8, 2012, at 9:16 AM, lina wrote:
> Hi,
>
> Here is the to-be-processed file,
>
> $ more try
> # RESIDUE AA STRUCTURE BP1 BP2 ACC N-H-->O O-->H-N
> N-H-->O O-->H-N TCO KAPPA ALPHA PHI PSI X-CA Y-CA
> Z-CA
> 1 174 V 0 0 0 0, 0.0 2,-0.3 0,
> 0.0 0, 0.0 0.000 360.0 360.0 360.0 137.8 47.8 27.7 76.9
> 2 175 H - 0 0 0 2,-0.0 2,-0.3 0,
> 0.0 0, 0.0 -1.000 360.0-153.6-152.0 146.1 50.8 25.5 78.2
>
> I wish to print the value under the BP1, namely
>
> 0
> 0
>
> but no matter count from left or right, the field number is uncertain,
>
> Thanks ahead for your suggestions,
Your data lines appear to have a fixed format, with fields separated by space
characters. If this is true, then you can use either the unpack or substr
functions to access a fixed set of characters from each record;
#!/usr/local/bin/perl
use strict;
use warnings;
while(<DATA>) {
next if /^\s*#/;
my( $bp1 ) = unpack('x23 A6');
print "bp1 = '$bp1'\n";
}
__DATA__
# RESIDUE AA STRUCTURE BP1 BP2 ACC N-H-->O O-->H-N N-H-->O
O-->H-N TCO KAPPA ALPHA PHI PSI X-CA Y-CA Z-CA
1 174 V 0 0 0 0, 0.0 2,-0.3 0, 0.0 0,
0.0 0.000 360.0 360.0 360.0 137.8 47.8 27.7 76.9
2 175 H - 0 0 0 2,-0.0 2,-0.3 0, 0.0 0,
0.0 -1.000 360.0-153.6-152.0 146.1 50.8 25.5 78.2
This line would also work:
my $bp1 = substr($_,23,6);
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/