in reply to Saving array duplicates, not using a hash?
The author knows there are many ways to solve each exercise with Perl, and your real task here is simply to figure out at least one way to do it and move on to the next exercise or the next chapter. If hashes have been mentioned at all prior to this particular exercise, then use a hash. Even if the book hasn't mentioned hashes yet, but you know about them from studying other sources, use a hash and move on. You should not assume that the author wants you to come up with some other sub-optimal solution that will be of no use to you in the future.
As you get further along in that book, if you find this sort of exercise being repeated with a focus on using hashes, you'll just get through that part more quickly because you've already learned it.
I know of a teaching method that works like this: (1) introduce some basic tools; (2) build familiarity and facility with these using simple exercises; (3) introduce more complex exercises, forcing students to do lots of tedious, mind-numbing, time-consuming work; (4) introduce some advanced tools and show how the more complex problems can be solved quickly and easily.
This was the method used when I was first introduced to calculus in high school, and it was pretty effective, but it takes a lot longer than just saying "when you have this sort of problem, here is the quickest, easiest way to solve it." These days (nearly 40 years later), I tend to favor the latter approach -- life is short, and you should take the long way around only if you really enjoy doing that and it holds some greater value for you personally (and you actually have the extra time to spare).
|
|---|