PerlArray wrapper will be created, multiple visits of the same ARRAY will use the same wrapper, i.e the same instance of a
The wrapper holds a reference to the ARRAY, this means that if you modify it, the changes are visible from perl side (if you hold a reference there). If the array has perl magic, for example if its
$ctx->bind_value(Argv => \@ARGV);
PerlArray instances inherit from
PerlArray instances inherits, via its prototype chain, all the methods and properties from Object. You can even set non-numeric properties in them, but those changes will not be normally visible from perl space.
var array = new PerlArray(...);
The arguments are use to initialize the array.
var parray = new PerlArray(3, 4, 'foo', someval);
When those objects land in perl space they will be normal perl ARRAYs, i.e. with out any "magic".
Instances of PerlArray can be accessed as a normal arrays using integer indexes. If a negative index is used it is relative to the tail.
parray.length; // Get the length of parray parray.length = fill; // Change the length of parray
lengthis the actual number of items in the array.
You can set this property to modify the length of the array, similar to Perl's
$#array = $fill. Remember:
lengthis the number of elements while
$#arrayis the index to the last one.
When the array is extended the new elements will be
undefin Perl). When the array is truncated, the excess elements are freed.
parray.length = 0;effectively clears the array.
The more common are:
- push(arg1, ...)
Pushes the arguments onto the array.
- unshift(arg1, ...)
Unshifts (i.e. inserts at the beginning) the arguments into the array.
- pop( )
Returns the top element.
- shift( )
Returns the bottom element.
- join( )
Returns a string with all the array elements, converted to strings if necessary, concatenated with
joinexp, by default
','if none provided.
- slice( )
- slice(begin, end)
Returns a new one level deep copy of the array, from
beginisn't provided defaults to 0, if
endisn't provided defaults to the index of the last element.
Note that the array isn't changed in any way. A new Array is created and returned.
- reverse( )
Reverse the array in place. The reversed array is returned
- sort( )
- sort( sorter )
This will sort the array in place. In the first form, without an argument, the sort will be in lexicographical order.
In the second form,
sorteris a function used to perform the comparations of the array elements. If supplied, the array elements are sorted according to the return value of the compare function. If
bare two elements being compared, then:
sorter(a, b)is less than 0, sort
ato a lower index than
sorter(a, b)returns 0, leave
bunchanged with respect to each other, but sorted with respect to all different elements.
sorter(a, b)is greater than 0, sort
bto a lower index than
sorter(a, b)must always returns the same value when given a specific pair of elements a and b as its two arguments. If inconsistent results are returned then the sort order is undefined.
The sorted array is returned.
- toString( )
Joins the array and returns one string containing each array element separated by commas.
- indexOf(searchElement, fromIndex)
Returns the first index at which a given
searchElementelement can be found in the array, or -1 if it is not present. The search starts at
fromIndex, if provided or from the beginning if not.
- lastIndexOf(searchElement, fromIndex)
Returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at
fromIndexif provided or from the end if not.
- toSource ( )
Returns a string that when evaluated recreated the PerlArray.
// Asumes 'parray' as defined above say(parray.toSource()); // "new PerlArray(3,4,'foo',someval)"
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 194:
=over without closing =back