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
length is 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:
length is the number of elements while
$#array is the index to the last one.
When the array is extended the new elements will be
undef in Perl). When the array is truncated, the excess elements are freed.
parray.length = 0; effectively clears the array.
The more common are:
Pushes the arguments onto the array.
Unshifts (i.e. inserts at the beginning) the arguments into the array.
Returns the top element.
Returns the bottom element.
Returns a string with all the array elements, converted to strings if necessary, concatenated with
joinexp, by default
',' if none provided.
Returns a new one level deep copy of the array, from
begin isn't provided defaults to 0, if
end isn'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 the array in place. The reversed array is returned
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,
sorter is 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
b are two elements being compared, then:
sorter(a, b) is less than 0, sort
a to a lower index than
sorter(a, b) returns 0, leave
b unchanged with respect to each other, but sorted with respect to all different elements.
sorter(a, b) is greater than 0, sort
b to 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.
Joins the array and returns one string containing each array element separated by commas.
Returns the first index at which a given
searchElement element 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.
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
fromIndex if provided or from the end if not.
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:
=over without closing =back