r*****o 发帖数: 28 | 1 I only know how to read a file line by line
or read in the whole file as a string.
But how to read/match multiple lines conditionally?
e.g. a file contains certain lables:
xxx
yyy
Begin: zzz
aaa
bbb
Ene: ccc
ddd
I need the script to read/match multiple lines between the Begin/End
pair as a single string. But for other lines, just read
them one by one.
Is there any easy way to do this?
Thanks. | l*****k 发帖数: 587 | 2 here is part of my code for this:
# it searches to the >$name, which is the alignment part for that hit
# it reads all info till the next > to $&
# $result get this info for further process
#
while($align=~ /^>$name.*\n(^(?!>).*\n)+/gm) {
$result = $&;
for your purpose, just change the second > into end, first > into begin, I bet
it should work.
and I am sure you are doing some sequence pars
【在 r*****o 的大作中提到】 : I only know how to read a file line by line : or read in the whole file as a string. : But how to read/match multiple lines conditionally? : e.g. a file contains certain lables: : xxx : yyy : Begin: zzz : aaa : bbb : Ene: ccc
| r*****o 发帖数: 28 | 3 Sorry, I am a novice on Perl and don't quite understand your script.
I assume the $align is the big string for a whole file.
And I think it works to strip out multiple lines in a certain block,
but what about other lines? Can it read them out one by one?
(I think if only to match out certain blocks, isn't .. or ... operators
a better way?)
Another question is how to match nested blocks? e.g.
(block ...
(block ...
...
(block ...
))
)
Is there any way to match the whole outer bloc
【在 l*****k 的大作中提到】 : here is part of my code for this: : # it searches to the >$name, which is the alignment part for that hit : # it reads all info till the next > to $& : # $result get this info for further process : # : while($align=~ /^>$name.*\n(^(?!>).*\n)+/gm) { : $result = $&; : for your purpose, just change the second > into end, first > into begin, I bet : it should work. : and I am sure you are doing some sequence pars
| r*****o 发帖数: 28 | 4 After lots of experiments and head-scratch,
I think I can now match the out-most block
(For clarity, I write it in multiple lines:
m{\(
.*?
\( [^\)]*
\)
}gx |
|