Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: extract relevent lines according to array

by nvivek (Vicar)
on Apr 19, 2010 at 09:08 UTC ( #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


Comment on Re: extract relevent lines according to array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2015-07-29 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls