Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Error in Code: Need help

by Util (Priest)
on Mar 28, 2012 at 23:27 UTC ( #962279=note: print w/replies, xml ) Need Help??


in reply to Error in Code: Need help

You can also make your code more robust by using the existence of the gene in the has instead of keeping "old" copied of the variables. This will allow your code to do-the-right-thing even when genes are in non-contiguous lines.

++tangent, who I see beat me to it.

#!perl use strict; use warnings; use autodie; my $out_path = 'output.txt'; my @lines = <>; chomp @lines; my %gene_maxfreq; for (@lines) { my ( $freq, $gene ) = split; my $max_freq = $gene_maxfreq{$gene}; if ( (!defined $max_freq) or $max_freq < $freq ) { $gene_maxfreq{$gene} = $freq; } } open my $out_fh, '>', $out_path; for (@lines) { my ( $freq, $gene ) = split; my $max_freq = $gene_maxfreq{$gene}; if ( defined $max_freq ) { my $line = join "\t", $freq, $gene, $max_freq; print {$out_fh} "$line\n"; print "$line\n"; } } close $out_fh;

Replies are listed 'Best First'.
Re^2: Error in Code: Need help
by angerusso (Novice) on Mar 29, 2012 at 00:24 UTC

    THANKS SO MUCH for your another SUPERCOOL code and help. Very much appreciated.!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-06-04 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?