If you structure your data a little differently, it will be easier to extract what you need:
use strict; use warnings; use List::Util qw(max min); my %gene_hash; while (<DATA>) { chomp; my ($chr, $start, $end, $gene, $ex) = split /\t/; push @{ $gene_hash{$chr}{$gene}{start} }, $start; push @{ $gene_hash{$chr}{$gene}{end } }, $end; push @{ $gene_hash{$chr}{$gene}{ex } }, $ex; } for my $chr (keys %gene_hash) { for my $gene (keys %{ $gene_hash{$chr} }) { my $Low = min( @ { $gene_hash{$chr}{$gene}{start} } ); my $High = max( @ { $gene_hash{$chr}{$gene}{end } } ); my $High_ex = max( @ { $gene_hash{$chr}{$gene}{ex } } ); print "$chr $Low $High $gene $High_ex\n"; } } __DATA__ chrX 2680092 2744539 XG 1 chrX 2680090 2744529 XG 2 chrX 2680080 2744519 XG 3 chrX 2680070 2744509 XG 4 chrX 2680070 2744509 DT 1 chrX 2680090 2744519 DT 2

prints out:

chrX 2680070 2744539 XG 4 chrX 2680070 2744519 DT 2

In reply to Re: How to group by a column and calculate max/min on another by toolic
in thread How to group by a column and calculate max/min on another by perl_paduan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.