Module::Generic::Array - An Array Manipulation Object Class
my $ar = Module::Generic::Array->new( [qw( Joe John Mary )] ); printf( "There are %d people\n", $ar->length ); # Adding one more $ar->push( "Jack" );
The purpose of this class/package is to provide an object-oriented approach at array manipulation
Provided with an optional array reference or an array object such as Module::Generic::Array, this will create a new object and return it.
Returns an hash reference with the keys being the array elements and the hash values their offset value.
Provided with an offset value and an optional length, and this will remove data from the array at the given offset and for the given length.
If no given length is provided, it removes all entries from the offset until the end.
It returns a list of elements removed in list context or an array reference of it in scalar context.
Returns the next element in the array.
Provided with a value and this returns the number of match, as an Module::Generic::Number object, if it is found in the array, or false otherwise.
Provided with a subroutine reference and this will call the subroutine reference, passing it the offset number and the corresponding array value.
$ar->for(sub { my( $i, $val ) = @_; # do something })
It returns the object itself so this can be chained.
Provided with a subroutine reference and this will call the subroutine reference, passing it the value for each entry in the array.
$ar->foreach(sub { my $val = shift( @_ ); # do something })
Provided with some data, and this will do a grep on the array.
It returns a list of matches found in ilst context and a new Module::Generic::Array in scalar context.
Provided with a string, or expression just as documented in "join" in perlfunc and this will return a string as an <Module::Generic::Scalar object.
This works as documented in "keys" in perlfunc and returns a list of offset values for each entry in the array.
Returns the size of the array, starting from 1, as a Module::Generic::Number object.
Provided with a reference to a subroutine and this will call the subroutine for each element of the array and return the result.
Returns the last entry in the array.
Provided with some data and this adds it at the end of the array.
Provided with an array reference, and this add all its entry at the end of the array.
my $ar = Module::Generic::Array->new( [qw( John Joe Mary )]); $ar->push_arrayref( [qw( Jack Peter )] ); print( $ar->join( "," ), "\n" ); # Now prints: John, Joe, Mary, Jack, Peter
This empty the array, just like "undef"
Returns a the array in reverse order in list context or a new Module::Generic::Array object of it in scalar context.
Provided with an array or an array-based object and this replace all the data in the current object by the ones provided.
Remove the first entry and returns it.
Returns the size of the array starting from 1, and 0 if the array is empty, as a Module::Generic::Number object.
Sort the array and return the new array as a list in list context or a new Module::Generic::Array object in scalar context.
Takes the same arguments as the "splice" in perlfunc function and returns the result.
Just like the normal "split" in perlfunct function, it takes a string or expression and split the data provided into a list of elements.
It returns the list in list context, and returns a new Module::Generic::Array object in scalar context.
Just like "reset", this empty the array.
This add the given values at the beginning of the array.
Get a list of all the array values and return a list in list context or a ne Module::Generic::Array object in scalar context.
Module::Generic::Scalar, Module::Generic::Number, Module::Generic::Boolean, Module::Generic::Hash, Module::Generic::Dynamic
Jacques Deguest <jack@deguest.jp>
Copyright (c) 2000-2020 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install Module::Generic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Generic
CPAN shell
perl -MCPAN -e shell install Module::Generic
For more information on module installation, please visit the detailed CPAN module installation guide.