In Perl, how can I read portions of strings that match the criteria?

Sample data:

603       Some garbage data not related to me, 55, 113 ->

1-ENST0000        This is sample data blh blah blah blahhhh
2-ENSBTAP0        This is also some other sample data
21-ENADT)$        DO NOT WANT TO READ THIS LINE. 
3-ENSGALP0        This is third sample data
node #4           This is 4th sample data
node #5           This is 5th sample data

This is also part of the input file but i dont wish to read this. 
Branch -> 05 13, 
      44, 1,1,4,1

17, 1150

637                   YYYYYY: 2 : %

EDIT: In the above data. The column width is fixed for sections, but there may be some sections that I do not want to read. The above sample data has been edited to reflect.

So, in this input file I want to read the contents of the first section "1-ENST0000" into an array and the contents of "2-ENSBTAP0" into a separate array and so on.

I am having problems with the appearance of a regular expression that will determine the pattern ... the first three lines have <someNumber>-ENS<someotherstuf>, and then maybe alsonode #<some number here>

0
source share
2 answers

, , . , , node #54 .

: , .

: , Perl.

: , , , , . if.

#!/usr/bin/perl

use strict;
use warnings;

my @data;

while ( <DATA> ) {
    chomp;

    if ( /^[0-9]+-ENS.{5} +(.+)$/
            or /^node #[0-9]+ +(.+)$/
    ) {
        push @data, [ split //, $1 ];
    }
}

use Data::Dumper;
print Dumper \@data;

__DATA__
603       Some garbage data not related to me, 55, 113 ->

1-ENST0000        This is sample data blh blah blah blahhhh
2-ENSBTAP0        This is also some other sample data
21-ENADT)$        DO NOT WANT TO READ THIS LINE. 
3-ENSGALP0        This is third sample data
node #4           This is 4th sample data
node #5           This is 5th sample data

This is also part of the input file but i dont wish to read this. 
Branch -> 05 13, 
      44, 1,1,4,1

17, 1150

637                   YYYYYY: 2 : %

, , perldoc perltoc.

0

? , . , , columen 1.

+1

All Articles