Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: how do i obtain blast result from the given file

by bingalee (Acolyte)
on Jun 17, 2013 at 19:59 UTC ( #1039460=note: print w/ replies, xml ) Need Help??


in reply to Re: how do i obtain blast result from the given file
in thread how do i obtain blast result from the given file

correction- I'm so sorry, I meant the first ten hits


Comment on Re^2: how do i obtain blast result from the given file
Re^3: how do i obtain blast result from the given file
by rjt (Deacon) on Jun 17, 2013 at 20:15 UTC

    In that case, just modify the initial loop to stop after ten hits:

    my $how_many = 10; while (<$fh>) { if (/^(.+?)\|(.+?)\| (.+?)\s+(\d+)\s+(\d+e[+-]\d+)$/) { print; last if --$how_many == 0; } }

    If that's all you want to do, you don't need the hash. Note that you can still format the output with printf: printf "%-4s %-55s %5s\n", $1, $3, $4;

    You could still use the hash, as well, if you need to do further processing on the results. In that case, to preserve the order, either add an index to the hash ref for use with sort, or, simpler, push each key to an array as you find them:

    my @hits; # Keys in order my $how_many = 10; while (<$fh>) { if (/^(.+?)\|(.+?)\| (.+?)\s+(\d+)\s+(\d+e[+-]\d+)$/) { $hash{$2} = { col1 => $1, desc => $3, score => $4, E => $5, key => $2 }; push @hits, $2; last if --$how_many == 0; } } # Go through the first ten hits, in order for (map { $hash{$_} } @hits) { # $_ contains the hash ref for each record printf "%-5s %-55s %5s\n", $_->{col1}, $_->{desc}, $_->{score}; }

      thank you :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-10-31 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls