arhuman has asked for the wisdom of the Perl Monks concerning the following question:

I was re-reading the camel book, and I was puzzled by a sentence which says (Translated back to english from my french camel book, I hope it'll make sense) :

You can put an optional comma at the end of every list. It will make further item addition easier

@numbers = (
1,
2,
3,
);

I was wondering what does that easy mean ?

Will be item addition faster ?
Will item addition use memory more wisely ?

I've even played with timethese to see if the former was the answer but I must admit that I didn't had any result (In fact I'm almost sure that anyway I'm not testing the right way...)

So here are my questions :

What does it means ?
and
Where can I find answer to those kind of questions (except in the perl sources which are beyond my understanding at the present time (and for a long time anyway ;-) ?

I've ordered 'advanced programming'; can you Perl gurus suggest me another book or another source of information ?

Replies are listed 'Best First'.
Re: Optimized array
by chipmunk (Parson) on Feb 20, 2001 at 00:44 UTC
    It's "easy" solely in terms of the programmer modifying the code. Always putting a comma at the end of the array prevents errors like the following:
    # before @array = ( 'dog', 'cat', 'fish' ); # after @array = ( 'dog', 'cat', 'fish' 'bird', 'rabbit' );
    Including the trailing comma means when you add new items to the array, you don't have to do anything besides adding the new items.
Re: Optimized array
by chromatic (Archbishop) on Feb 20, 2001 at 00:45 UTC
    I use it to save programmer time and to keep me from making really stupid errors.

    Those times I don't use it with a hash or an array, I usually go back, add a new item on a new line, and have to debug the missing comma error. I'm pretty sure that's what the authors meant.

    And the book from which I've learned the most besides the Camel is Object Oriented Perl. Even if you don't do a lot of OO Perl, there's bundles of good stuff in there.

Re: Optimized array
by arturo (Vicar) on Feb 20, 2001 at 00:39 UTC

    Probably the authors just meant "if you want to type in more members of the list," i.e. you won't have to add the comma to the previous line should you want to go on and add 4 to @numbers.

    reference : p. 48 of 2nd edition of Programming Perl, this is my interpretation.

    Update Grist for my interpretive mill: note the multiple kinds of efficiency discussed in Ch. 8, one of which is "Maintainer Efficiency", which applies to the present case quite nicely.

    Second update : I don't proclaim guru-hood, but I'd suggest Effective Perl Programming, and second chromatic's suggestion about Conway's Object-Oriented Perl. You might also take a look at the Reviews section and see if any of the books there catch your interest.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor