Tie::Subset::Array - Tie an array to a subset of another array
use Tie::Subset::Array; my @array = (55,66,77,88,99); tie my @subset, 'Tie::Subset::Array', \@array, [1,2,3]; print "$subset[1]\n"; # prints "77" $subset[2]++; # modifies $array[3]
This class for tied arrays provides a "view" of a subset of an array.
tie
tie my @subset, 'Tie::Subset::Array', \@array, \@indices;
You must specify which subset of indices from the original array should be part of the new array. (Indices that do not yet exist in the original hash may be specified.) The subset (tied array) will be the same size as @indices, and is indexed by the usual 0 to $#subset.
@indices
$#subset
If the index is within the bounds of the tied array, the value from the underlying array is returned, otherwise returns nothing (undef).
If the index is within the bounds of the tied array, the new value will be stored in the underlying array, otherwise the operation is ignored and a warning issued.
exists
Note: The Perl documentation strongly discourages from calling exists on array values.
Will return true only if the index exists in the subset and the corresponding index in the underlying array exists.
Any operations that modify the size of the tied array are not (yet) supported (because it is ambiguous how such operations should affect the underlying array). Attempting to change the tied array's size, including using push, pop, shift, unshift, splice, assigning to the $#array notation, clearing the array, etc. will currently do nothing and cause a warning to be issued, and operations that normally return a value will return nothing.
push
pop
shift
unshift
splice
$#array
The above is also true for attempting to delete array elements, which the Perl documentation strongly discourages anyway.
delete
A future version of this module may lift these limitations (if a useful default behavior exists).
"See Also" in Tie::Subset
Copyright (c) 2018 Hauke Daempfling (haukex@zero-g.net).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command perldoc perlartistic or see http://perldoc.perl.org/perlartistic.html.
perldoc perlartistic
To install Tie::Subset, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Subset
CPAN shell
perl -MCPAN -e shell install Tie::Subset
For more information on module installation, please visit the detailed CPAN module installation guide.