new19 has asked for the wisdom of the Perl Monks concerning the following question:

my sequence is like that i want to extract the two 5 digits number using the split function .how i can do that scaffold_12147 protein_coding exon 32192 32242 . - . gene_id "ENSTBEG00000007763";

#!/usr/bin/perl use warnings; use strict; my @records; open FILE, "vik.txt" or die $!; while(<FILE>) { chomp; my @columns = split ' ', $_; push @records, \@columns; } foreach my $record(@records) { if ($record->[2] eq "exon") { split ('d+',@$record); print "$record \n"; } }

Replies are listed 'Best First'.
Re: string problem
by moritz (Cardinal) on Mar 31, 2011 at 12:01 UTC
    t i want to extract the two 4 digits number using the split function .how i can do that scaffold_12147 protein_coding exon 32192 32242 . - . gene_id "ENSTBEG00000007763";

    I see three 5-digit numbers and one 11-digit number. Where are the two 4-digit numbers you mentioned?

    I think you need to be more specific about what you want.

    See also: How (Not) To Ask A Question.

      oh i am sorry the 5 digit numbers
Re: string problem
by Marshall (Canon) on Apr 02, 2011 at 19:51 UTC
    You could also just use a match global to extract all 5 digit numbers that are preceded by a space.
    #!/usr/bin/perl -w use strict; my $text = 'scaffold_12147 protein_coding exon 32192 32242 . - . gene_ +id "ENSTBEG00000007763'; my @numbers = ($text =~ /\s(\d{5})/g); print "@numbers\n"; #prints 32192 32242
    Update: slight wrinkle:
    #!/usr/bin/perl -w use strict; open FILE, "vik.txt" or die $!; while(<FILE>) { my ($exon, $number1, $number2) = (split /\s+/, $_)[2,3,4]; if (defined ($exon) and $exon eq "exon") { print "$number1 $number2\n"; } }