# -*- cperl -*- =head1 Perl Array PMC =head2 Creation To create a new PMC with a PerlArray object: new P0, .PerlArray =head2 Size Perl array can be initialized to the empty array using set P0, 0 and we can check the PerlArray size, putting the value on register C using set I0, P0 We can create an empty array but with some chunks allocated. This method is the same to initialize the array to the empty array. In this case, use the number of chunks you want: set P0,5 =head2 Index access You can set the value 3 on the position 5 from the array using set P0[5] 3 In the same mood, to access the element use set I0, P0[5] As in Perl, negative indexes are seen as indexes from the end of the array. This way, you can set the last element of the array to the value 7 using set P0[-1], 7 Note that you can put on each chunk a integer, number, string or PMC. You must have caution when accessing the value, as you should use the correct type of register. =head2 Using keys of different types You can use string or numbers as indexes for the array if they represent an integer. So, these are correct instructions: set P0[5.0], 3 set P0["10"], 6 set P0[15], 9 which sets values on positions 5, 10 and 15. =head2 Trueness You can get a boolean value from a Perl Array. If you use an empty Perl Array in a condition, it will return false (no elements). new P0, .PerlArray if P0, JUMP # This will never succeed After adding a value (for example, P0[0] = 1), it will return a true value (the Perl Array has elements). new P0, .PerlArray set P0, 0, 1 if P0, JUMP # This will succeed If you don't add a value, but force a size different from zero the the array, it will return a true value: new P0, .PerlArray set P0, 1 if P0, JUMP # This will succeed =cut