Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2010/10/15

Array of Troubles

This is perfectly legal Perl.
my @x = ( 1 ,2 ,3, 4, ) ;
This can be useful when you have things you want to add to or move around, not having to be sure to remove the last comma and add one if you move up the last element.

Compare this SQL.
SELECT foo , bar , blee  , FROM quuz ;

That'll give you an error. In one sense, well, sure. On the other hand, it sucks because the same dynamic forces that happen as you program in Perl come forth as you develop SQL queries.

I suppose the solution is to put a kind of null into the last field so you can shuffle until the cows come home, but I'm still frustrated.

3 comments:

  1. The same thing is true in JSON, which really sucks! I mean, it would be bad enough if it were just JavaScript, but it's not; we use JSON in a lot of places.

    ReplyDelete
  2. I had already been thinking of this before, but now your article has inspired me to make my Muldis D language (for object-relational databases) support Perl's trailing comma syntax, where before it disallowed this like SQL does. This update is part of version 0.142.0 of the spec that has been uploaded to CPAN an hour ago.

    ReplyDelete
  3. I've seen to use the following in JS:

    , item1
    , item2
    , item3

    so you can cut and paste lines without worring by the last ','

    Nice post

    ReplyDelete