Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl sorting unique values

by Utilitarian (Vicar)
on Jun 22, 2011 at 08:43 UTC ( [id://910870]=note: print w/replies, xml ) Need Help??


in reply to Perl sorting unique values

If ever you find yourself thinking "I need to get the unique values of $THING" you should consider using a hash, iterating through the values for $F[2] and incrementing $hash_of_f2{$F[2]} would give you a set of unique values available as keys %hash_of_f2 which you could then sort

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: Perl sorting unique values
by pr09 (Novice) on Jun 22, 2011 at 09:21 UTC
    my %hash; open (FILE,"abc.txt"); while (<FILE>) { chomp; my ($key,$val) = split '\|'; print $hash{$val}; }
    This is a bit of code which i have written,i did not applied sort on it till now.But,its not working.

      Almost there:

      use strict; use warnings; my %hash; open my $fh, '<', 'abc.txt' or die $!; while (<$fh>) { chomp; my ($key, $val) = split '\|'; $hash{$val}++; } print "$_\n" for sort keys %hash;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2025-06-20 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.