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

Re^3: Build your array with push

by integral (Hermit)
on Jan 31, 2006 at 19:40 UTC ( #526859=note: print w/replies, xml ) Need Help??

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

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

Replies are listed 'Best First'.
Re^4: Build your array with push
by ikegami (Pope) on Feb 06, 2006 at 17:45 UTC

    No, it does not.

    $ cat > a.c int a[] = (1,2,3,); $ gcc -c a.c a.c:1: error: syntax error before ')' token

    Not even in C++

    $ cat > a.cpp int a[] = (1,2,3,); $ gcc -c a.cpp a.cpp:1: error: expected primary-expression before ')' token

      It helps to remember that in C you need to use {} as brackets around a compound initialiser (something which is different from perl, where , has taken on a much greater role).

      thaum:/tmp bsmith$ cat >a.c int a[] = { 1, 2, 3, }; thaum:/tmp bsmith$ gcc -c a.c thaum:/tmp bsmith$

      integral, resident of freenode's #perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://526859]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2017-06-29 00:47 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (653 votes). Check out past polls.