Author image Hauke D
and 1 contributors


Tie::Subset - Tie an array or hash to a subset of another array or hash, respectively


 use Tie::Subset;
 my %hash = ( foo=>11, bar=>22, quz=>33 );
 tie my %subset, 'Tie::Subset', \%hash, ['bar','quz'];
 # same as tie-ing to 'Tie::Subset::Hash'
 my @array = (55,66,77,88,99);
 tie my @subset, 'Tie::Subset', \@array, [1,2,3];
 # same as tie-ing to 'Tie::Subset::Array'


This class simply delegates to Tie::Subset::Hash or Tie::Subset::Array as appropriate. Please see the documentation of those modules.

See Also


The module Tie::Subset::Array is primarily provided for orthogonality with Tie::Subset::Hash. The following "trick" can be used to get an array reference where the elements are aliases to the original array:

 my $subset = sub { \@_ }->( @array[@indices] );

However, note there are differences between the behavior of this code and Tie::Subset::Array with respect to array indices that lie outside of the range of either array. For details, please see the file t/80_alias.t that is part of this module's distribution.

Author, Copyright, and License

Copyright (c) 2018 Hauke Daempfling (

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