|XP is just a number|
Re: ASCII fileby pemungkah (Priest)
|on Jan 26, 2012 at 22:17 UTC||Need Help??|
Here's how I would write this program:
First, figure out what I would do if I wasn't using a computer:
Next, you'll need a table that maps one thing to another (a character name to a count), so you'll probably want to read up on hashes and how they work, since hashes let you map a key (in this case a character) to some other value (in this case a count).
You'll want to loop over the input while there is some, so read up on while loops.
Finally, you'll want to print things out in order, so you'll want to look at the Perl FAQ to see if there's a hint on sorting a hash.
From here, it's a matter of putting the pieces together and creating the final program. This is really all programming is: looking at what you want to do, and mapping that into the tools you have to do it with. The creative part of programming is realizing how you can use your tools better, faster, or more simply to do the job.
Note that this is not a program, but an insight into how to think about a problem so you can write a program, which is the solution you actually need - it's not always possible to find someone who can whip a program out for you. This time, there was an answer - but it's not always that simple. If you teach yourself how to think about problems so you can break them down into pieces that you know work, then it's "easy" to program. Perl is really good for this as with CPAN there is an immense toolbox of stuff that is known to work for bigger problems: parsing XML, fetching pages from the Web, etc.