Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I compare Values from a Hash

Status
Not open for further replies.

spalmarez

IS-IT--Management
Aug 17, 2005
7
US
I am trying to get the lowest value from my dtt value. I have multiple mcc's. How can I achieve this? Here is my list:

MOD,MCC,DTT
13976465,80492.1, 65535
13976465,81402.1, 21600
13976417,80664.1, 65535
13976417,80431.1, 800

$hash{$key}{mcc}{$mcc}=$mcc;
$hash{$key}{mcc}{$mcc}{dtt}=$dtt;
 
this way will give you the lowest value of all the columns:-

Code:
[b]#!/usr/bin/perl[/b]

while (<DATA>) {
  @cols = split(/,/);
  push @mod, $cols[0];
  push @mcc, $cols[1];
  push @dtt, $cols[2];
}

@mod = sort {$a <=> $b} @mod;
@mcc = sort {$a <=> $b} @mcc;
@dtt = sort {$a <=> $b} @dtt;

print $mod[0] . "\n";
print $mcc[0] . "\n";
print $dtt[0] . "\n";

[blue]__DATA__
13976465,80492.1,65535
13976465,81402.1,21600
13976417,80664.1,65535
13976417,80431.1,800[/blue]


Kind Regards
Duncan
 
Thanks. I was making it harder than what it was.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top