Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: extract relevent lines according to array

by nvivek (Vicar)
on Apr 19, 2010 at 09:08 UTC ( [id://835415]=note: print w/replies, xml ) Need Help??


in reply to extract relevent lines according to array

You try the following script to do it.
use strict; use warnings; use Data::Dumper; my $chrom='chr1'; my $start=9839; my $stop=9841; my %hash=(); my @values=(); while(<DATA>) { if(/[a-z]+\s*chrom=$chrom/) { while(<DATA>) { if(/([0-9]+)\s*([0-9]+\.[0-9]+)/) { $hash{$1}=$2; } else { last; } } } } for ($start .. $stop) { push @values,$hash{$_}; } print @values; __DATA__ variableStep chrom=chr1 9837 0.010 9838 0.008 9839 0.007 9840 0.004 9841 0.002 9842 0.001 variableStep chrom=chr2 9837 0.090 9838 0.038 9839 0.017 9840 0.044 9841 0.052 9842 0.091

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://835415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-23 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found