regex - Storing Numerical Data in a Variable through matching in Perl -
i beginner @ perl , want store data file format variable. specifically, each line of file has format following:
atom 575 cb asp 2 72 -2.80100 -7.45000 -2.09400 c_3 4 0 -0.28000 0 0
i able use matching line wanted (with code below).
if ($line =~ /^atom\s+\d+\s+(cb+)\s+$residue_name+\s+\d+\s+$residue_number/) { }
however, want store 3 coordinate values variables or in hash. possible use matching store coordinate values rather having use substring.
in instance split
each record array , verify identifying fields. coordinate values can extracted array if line has been found relevant.
like this
use strict; use warnings; $residue_name = 'asp'; $residue_number = 72; while (<data>) { @fields = split; next unless $fields[0] eq 'atom' , $fields[2] eq 'cb' , $fields[3] eq $residue_name , $fields[5] == $residue_number; @coords = @fields[6, 7, 8]; print "@coords\n"; } __data__ atom 575 cb asp 2 72 -2.80100 -7.45000 -2.09400 c_3 4 0 -0.28000 0 0
output
-2.80100 -7.45000 -2.09400
Comments
Post a Comment