Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-02-19 14:39 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (265 votes). Check out past polls.