Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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


Comment on Re^3: Build your array with push
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-09-16 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (36 votes), past polls