NAME
Deep::Hash::Exists - verify existence of keys hash
SYNOPSIS
use Deep::Hash::Exists qw( is_exists );
my $hash_ref = {
A => 'one',
B => [ 'one', 'two' ],
C => {
'one' => 1,
'two' => 2,
},
};
if ( is_exists( $hash_ref, [ 'C', 'one' ] ) ) {
printf "Output: %d", is_exists( $hash_ref, [ 'C', 'one' ] );
}
# Output: 1
if ( is_exists( $hash_ref, [ 'D' ] ) ) {
printf "Output: %d", is_exists( $hash_ref, [ 'D' ] );
}
# Output: 0
DESCRIPTION
Exists hash:
my $hash_ref = {
A => 'one',
B => [ 'one', 'two' ],
C => {
'one' => 1,
'two' => 2,
},
};
If verify existence of keys standard way, will be created non existent keys:
exists $hash_ref->{C}{three}{PI}{0};
print Dumper $hash_ref;
Output:
# $VAR1 = {
# 'A' => 'one',
# 'B' => [
# 'one',
# 'two'
# ]
# 'C' => {
# 'one' => 1,
# 'two' => 2,
# 'three' => {
# 'PI' => {}
# }
# },
# };
Subroutine is_exists
does not create new keys:
is_exists( $hash_ref, [ 'C', 'three', 'PI', 0 ] );
print Dumper $hash_ref;
Output:
# $VAR1 = {
# 'A' => 'one',
# 'B' => [
# 'one',
# 'two'
# ],
# 'C' => {
# 'one' => 1,
# 'two' => 2
# }
# };
is_exists($$)
is_exists( $hash_ref, $array_ref_keys ) - verify existence of keys hash
Return:
1 - if exists hash key
0 - if not exists hash key
Example:
my $hash_ref = {
A => 'one',
B => [ 'one', 'two' ],
C => {
'one' => 1,
'two' => 2,
},
};
printf "Output: %s", is_exists( $hash_ref, [ 'A' ] );
# Output: 1
printf "Output: %s", is_exists( $hash_ref, [ 'B' ] );
# Output: 1
printf "Output: %s", is_exists( $hash_ref, [ 'B', 0 ] );
# Output: 0
printf "Output: %s", is_exists( $hash_ref, [ 'C', 'one' ] );
# Output: 1
printf "Output: %s", is_exists( $hash_ref, [ 'C', 'three' ] );
# Output: 0
printf "Output: %s", is_exists( $hash_ref, [ 'C', 'three', 'PI', 0 ] );
# Output: 0
# Subroutine does not create new keys.
SEE ALSO
COPYRIGHT AND LICENSE
Copyright (C) 2015 Vitaly Simul <vitalysimul@gmail.com>
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
AUTHOR
Vitaly Simul <vitalysimul@gmail.com>