Perl_Crazy has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance#!/usr/bin/perl open(FH, $ARGV[0]) || die("Cannot open:$!"); while (<FH>) { ($Query, $Score, $Start, $End, $one, $two) = split; if ( ! exists ( $hash{$Query} ) ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash{$Query}[1] > $Start ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } if ( ! exists ( $hash2{$Query} ) ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash2{$Query}[2] < $End ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } } foreach $Query ( keys (%hash) ) { foreach $Query ( keys (%hash2) ) { print "$Query\t$hash{$Query}[0]\t$hash{$Query}[1]\t$hash2{$Query}[2 +]\t$hash{$Query}[3]\t$hash{$Query}[4]\n"; } } close(FH); __DATA__ Books 6 159290954 159291342 + Author Books 6 159294558 159294653 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331385 + Author Books 6 159290971 159290997 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331289 + Author Books 6 159316268 159316398 + Author Books 6 159330999 159331245 + Author
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing and Finding Max Min
by almut (Canon) on Dec 30, 2009 at 14:03 UTC | |
|
Re: Parsing and Finding Max Min
by RMGir (Prior) on Dec 30, 2009 at 13:56 UTC | |
|
Re: Parsing and Finding Max Min
by Cristoforo (Curate) on Dec 31, 2009 at 02:18 UTC |