Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Build your array with push

by PhilHibbs (Hermit)
on Jan 31, 2006 at 16:15 UTC ( [id://526784]=note: print w/replies, xml ) Need Help??


in reply to Re: Build your array with push
in thread Build your array with push

Something in me really doesn't like that trailing comma, which I wouldn't have expected to work. I suspect it's just an old habit, as it doesn't work in C & C++, which is still there lurking at the back of my mind and occasionally poisoning the Perl code that I write. OK, I'll try and get used to it, and thanks for introducing me to it - I trust that it really has no effect.

Now to get back some of that lost XP by upvoting the helpful replies...
 ah, I like being a Friar anyway, it goes with my T-shirt.

Replies are listed 'Best First'.
Re^3: Build your array with push
by Roy Johnson (Monsignor) on Jan 31, 2006 at 16:44 UTC
    you don't have to merely trust; it's documented in perldata:
    You may have an optional comma before the closing parenthesis of a list literal
    In fact, you can have extra commas anywhere you want in a list except (for reasons I can't explain) at the very front of it. They will not cause undef items to be created, nor will including nested empty lists.
    my @items = ((),,,,5); print "<$_>\n" for @items; # prints only one item

    Caution: Contents may have been coded under pressure.
Re^3: Build your array with push
by integral (Hermit) on Jan 31, 2006 at 19:40 UTC

    Actually it does work in C, and that's most likely where perl picked up the habit too. One reason it's very useful is when you're generating code with macros, it's much easier to append commas to things than to insert them between things.

    --
    integral, resident of freenode's #perl
    
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://526784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found