Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Getting rid of duplicates

by terra incognita (Pilgrim)
on Sep 29, 2004 at 18:36 UTC ( [id://395097]=note: print w/replies, xml ) Need Help??


in reply to Getting rid of duplicates

Another one using a hash, this is a modified character frequency example from perlretut. This will sort and also handle negative numbers. Comments on where I can improve this code and what practices I should stay away from are appreciated.
use strict; local $/; my $f = <DATA>; my %chars; $f =~ s/(.+)/$chars{$1}++;$1/eg; # final $1 replaces char with itself print "'$_'\n" foreach (sort {$a <=> $b} keys %chars); __DATA__ 1 1 2 2 3 3 4 5 6 7 8 9 10 11 12 13 -12 -3

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found