kipo has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl %studente = ("Rakip Rusi"=>"9" , "Benard Musta"=>"4" , "Aleksander Gega"=>"1" , "Gentian Xhika"=>"7"); #how to compare them and then print name of the biggest #i need help for tomorrow #i am new in perl and is deficult for me!

Replies are listed 'Best First'.
Re: Compare hash !
by ikegami (Patriarch) on Nov 18, 2010 at 23:14 UTC

    [ I moved your post to Seekers of Perl Wisdom. Cool Uses for Perl is for showing off interesting or useful pieces of Perl code ]

    how to compare them

    Compare what to what?

    how to [...] print name of the biggest

    use strict; use warnings; use feature qw( say ); use List::Util qw( reduce ); my %students = ( ... ); my $highest = reduce { $students{$a} >= $students{$b} ? $a : $b } keys(%students); say $students{$highest};

    List::Util, say

Re: Compare hash !
by kennethk (Abbot) on Nov 18, 2010 at 23:18 UTC
      Sorting is not necessary to find a maximum.
        TIMTOWTDI, and you are literally correct. Given the apparent familiarity of the OP with the subject matter, I was assuming he would benefit more from direction and documentation than from code.
Re: Compare hash !
by NetWallah (Canon) on Nov 19, 2010 at 01:13 UTC
    If you care to study it, this code demonstrates completely how to solve your problem.
    perl -e "my %s=qw |dos 2 cinco 5 Uno 1 cuatro 4 tres 3|; $s{$_} > $s{ +$h}? $h=$_:0 for keys %s;prin t $h"

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis