Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Text Manipulation Quickie

by grummerX (Pilgrim)
on Aug 15, 2002 at 10:46 UTC ( [id://190358]=note: print w/replies, xml ) Need Help??


in reply to Text Manipulation Quickie

Try this:
#!/usr/bin/perl -w use strict; my %value; for (<DATA>){ chomp; $value{$_}++ if $_; } my $max = (sort map { $value{$_} } keys %value)[-1]; for my $count (1..$max){ for (sort keys %value){ print "$_\n" if $value{$_} >= $count; } } __DATA__ 2 2 2 3 3 3 4 4 4
Update:
For an uneven list as those Frankus mentions, this will work according to his first example, ie:
2
2
2
3
3
3
4
4
5
Will return:

2
3
4
5
2
3
4
2
3
You can make it work like his second example by reversing the loop:
for my $count (reverse 1..$max){

Update (2): Got rid of pesky newlines per katgirl.

-- grummerX

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found