Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Text Manipulation Quickie

by frankus (Priest)
on Aug 15, 2002 at 10:41 UTC ( [id://190357]=note: print w/replies, xml ) Need Help??


in reply to Text Manipulation Quickie

And for the file:
2
2
2
3
3
3
4
4
5
How would that be handled?
this    or  that?
2             2
3             3
4             2
5             3
2             4
3             2
4             3
2             4
3             5
Fundamentaly whay you need is this:
# Create an array of numbers with values... my %numbers = (); for (<FILE>){ chomp; $numbers{$_}++; # tally the occurences of numbers.. # Could add a preemptive 'last' if numbers not contiguous } while( %numbers ){ # satisfies "this" criteria, insert a reverse for "that" for ( sort keys %numbers ){ print "$_\n"; delete $numbers{$_} unless --$numbers{$_}; # Add a routine here to remove all higher values # and warn if numbers are non-contiguous. } }
If this is homework, please note we're not here to do your thinking for you, just to help you think in Perl.

--

Brother Frankus.

¤

Log In?
Username:
Password:

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

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

    No recent polls found