Re: Using regex special characters from a string



Thanks for the reading suggestions!

Brian Fraser wrote:
On Wed, Mar 9, 2011 at 2:22 PM, Brian F. Yulga <byulga@xxxxxxxxxxxxxxxxx <mailto:byulga@xxxxxxxxxxxxxxxxx>> 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).
.



Relevant Pages

  • Re: Using regex special characters from a string
    ... >> I'm wondering if I need to convert my hash of valid words into an array, ... 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. ... I understand that this is very inefficient in Perl, and that Perl is optimized to search and manipulate hashes and lists as a whole, rather than executing code over each item one-at-a-time. ...
    (perl.beginners)
  • Re: Nested arrays
    ... Against PHP, hashes are widely used in Perl. ... Perl makes a certain difference between hashes and arrays. ... assign a reference of an array to a hash key. ...
    (comp.lang.perl.misc)
  • Re: Learning Perl books
    ... inexperienced programmer wishing to use Perl on a Windows platform? ... Learning Perl book, ... Both are excellent books for learning the Perl programming language. ... it doesn't deal sufficiently with command line ...
    (perl.beginners)
  • Re: Idiom for array index that Im foreaching over?
    ... >you'll find that you rarely want to loop over an index. ... >array elements directly, and in fact map and grep do much of the looping. ... With hashes, indexed access, and hence loops ... simplicity and elegance that I expect out of good modern Perl ...
    (comp.lang.perl.misc)
  • Learning Perl - the Good and the Bad (Tutorials, Habits, and Tools, etc)
    ... I've been learning Perl in my spare time for the past week or so. ... want using references. ... It has been my experience in the past that once you know a language ...
    (perl.beginners)