Thanks for the reading suggestions!
Brian Fraser wrote:
On Wed, Mar 9, 2011 at 2:22 PM, Brian F. Yulga
<byu...@langly.dyndns.org <mailto:byu...@langly.dyndns.org>> wrote:
Uri and Jim have hit upon one of my major stumbling blocks with
learning Perl. There seems to be a difference of opinion on the
proper times to use hashes vs. arrays/lists...and how best to use
them.
http://perldoc.perl.org/perlfaq4.html#How-can-I-remove-duplicate-elements-from-a-list-or-array%3f
>>Use a hash. When you think the words "unique" or "duplicated", think
"hash keys".
Very informative! Also in the following section, "How can I tell
whether a certain element is contained in a list or array? Hearing the
word "in" is an indication that you probably should have used a hash,
not a list or array, to store your data."
Also the Hashes chapter of Learning Perl has a section called
something like "Why use Hashes," which seems fitting enough.
"counting words" is the fourth example :-) That section mentions that
hashes are useful for related data, or database-like data, but wasn't
entirely convincing for me because it didn't mention performance.
Same with the Hashes part of Modern Perl (
http://www.onyxneon.com/books/modern_perl/index.html ), in the "The
Perl Language" chapter.
For those that have heard of this book, I'm currently digesting
this piece of information:
Effective Perl Programming, 2nd Ed., Item 9: "Know the difference
between lists and arrays."
See Item 13: Use arrays or hashes to group data. Also,
www.effectiveperlprogramming.com
<http://www.effectiveperlprogramming.com>.
A useful read, but similar to Learning Perl, it doesn't mention the
performance aspect. In this situation, I think the perlfaq provides the
most convincing argument.
I don't know if others had this problem when learning Perl, but the
TMTOWTDI "philosophy" sometimes makes it difficult for me to discover
better ways of doing things after I find one clunky way that works
(hence my recent purchase of Effective Perl Programming, with the
intention of acquiring Perl Best Practices in the future).
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/