in reply to Re^2: array of arrays
in thread array of arrays

Hi L~R!

I don't know what "cargo culting" means. I asked about a homework assignment because this problem didn't seem "real-world" to me. Your points about non-numeric, etc are well taken.

One thing that newbies often miss is the power of Perl list processing. Most of the common languages iterate over some array with an index variable array[$i]. In Perl the way is to iterate over all elements and the index doesn't matter. There is a lot of literature about "off-by-one" errors. Processing a Perl list avoids this problem - there is no "index" variable. It becomes: for everything in this list, do "X".

I would go as far as to say that as one's experience in Perl increases, the use of [$i] decreases. Now of course there are very valid reasons to use this type of statement! But in general a new Perl'er will overuse this. The use of the Perl hash is also often underused.

Replies are listed 'Best First'.
Re^4: array of arrays
by Limbic~Region (Chancellor) on Jun 29, 2009 at 14:36 UTC
    Marshall,
    Please do read cargo cult then as it will be enlightening. In a nutshell, it means blindly following a ritual in the belief it will lead to the desired results. By telling someone who is presumably very new to perl that they should be using a HoA instead of an AoA because it is the more perlish way to do things without explaining why, could and has, resulted in someone always using a HoA even in situations when an AoA is better.

    I don't disagree with your position on the power of perl or how it is often misused or underutilized. My issue was that you didn't bother to explain yourself or even make your advice conditional upon stated assumptions. This can lead down the path of cargo culting.

    My opinion isn't shared by everyone and there are a number of good counter points. For more, see Breaking The Rules and Breaking The Rules II.

    Cheers - L~R

      I'm not an English major, but when I started with: "It sounds to me like you need a different data structure, a HoA (Hash of Array)", I reckon, "It sounds to me" implies some amount of uncertainty.

      I don't see a problem here. You are actually paying me a compliment by telling me that what I say does matter! I will strive to be better, but as a practical matter not every post (if any!) I write will ever be "perfect". I am not perfect, but I do try to be helpful in a constructive way.

      Software is devilishly tricky because there are "the heuristics" and then the exceptions to the "rule". Its a situation where in order to "break the rules", you have to know what the "rules are" and why they make sense, which I think goes to your point.