Note: we use the term 'list' interchangeably with 'array' here. Technically speaking we mean "reference to an array" when we say "reference to a list" and so on, but we don't worry too much about the distinction in TT land.
Note: all these methods can be called as subroutines, passing a reference to a hash array as the first argument.
my $hash = Template::TT3::Type::Hash->new( a => 10 ); $hash->keys(); # [ a ] my $data = { b => 20 }; Template::TT3::Type::Hash::keys($data); # [ b ] # lookup method from hash object, pass raw hash data as argument $hash->can('keys')->($data); # [ b ]
Constructor method to create a new hash array. A reference to a Hash object, hash array or a list of named parameters can be passed as argument(s) to define the contents of the Hash object. If a Hash object is passed as an argument then it is first cloned. If a reference to a hash array is passed then it is blessed into a Hash object without being copied. If a list of named parameters is passed then they are merged into a new hash array which is then blessed and returned as a Hash object.
Creates a new Hash object as a copy of the current one. A reference to a Hash object, hash array or a list of named parameters can be passed as argument(s) to define any additional data items to be added to the cloned Hash object.
Returns a reference to an unblessed hash array containing a copy of the current Hash object and any additional items passed by reference to another Hash object, hash array or as a list of named parameters.
Returns a text representation of the hash array. One or two optional
arguments can be provided. The first is used to define a delimiter to
be used between key/value pairs. The default value is =>
.
The second argument can be used to provide an alternate delimiter to be
used between successive pairs of items. The default value is
,
.
Returns a reference to a list containing the keys of the hash array, as per Perl's keys() function.
Returns a reference to a list containing the values of the hash array, as per Perl's values() function.
Returns a reference to a list containing the interleaved keys and values of the hash array.
Returns a reference to a list containing references to lists, each of which contains a key and value from the hash array.
Returns a reference to a list containing references to hash arrays, each of which contains a key and value from the hash array.
Sorts the values in the hash array alphabetically and returns a list of keys corresponding to that order. If you want a list of keys in sorted order, then simply call the keys() method and sort the values returned.
As per sort(), but returns the keys corresponding to the values sorted numerically.
Andy Wardley http://wardley.org