in reply to Hash to count characters
Both nvivek and jwkrahn gave you good tips on correcting your code while staying with your algorithm. However, I had a different route to get the character counts in a file. Instead of breaking the data down into words and then breaking it down further into characters, I say break down the data into the characters from the start.
I'll give you a hint at what I'm thinking about. Consider the following lines of code:
my $line = "This is sample data simulating a line from a file."; my (@chars) = ($line =~ m/([st])/gi);
Since you said that this was an assignment, this sounds like something you're doing for a class. That's why I'm just giving hints rather than saying "Here's the code to do your assignment.", which won't be much help for future assignments and tests.
If you really, really want to see code, check out my scratchpad. Just keep in mind that you copy my stuff verbatim, your teacher/instructor will probably realize that it's not your code since it won't match your code style and might use stuff that might not have been covered yet.
|
|---|