$key =~ m/^-?\d+$/-
For DiveRef(), if
$refis undefined, then it is autovivified into a reference to anonymous array. If$refcan act as a reference to an array, then$ref= $ref->[$key]is attempted. If $key is larger than $#$ref, then @$ref will grow. If $key is less than -@$ref, then Perl willdie.If
$refcannot act as a reference to an array, then $ref might be used as a reference to a hash as described further down. - a reference to an array
-
If $key can be used as a reference to an array, then it means that you might expect
$refto be a reference to a subroutine.If
UNIVERSAL::isa( $ref, 'CODE' )is true, then$ref->( @$key )is attempted.If $key isn't the last value in @ListOfKeys and the next value is undefined, then &$ref is called in a scalar context and $ref is set to refer to the scalar value returned.
Otherwise, &$ref is called in a list context and $ref is set to refer to an anonymous array containing the value(s) returned.
- any (defined) string
-
This means that you might expect
$refto be a reference to a hash.For Dive(), if
$refcan act as a reference to a hash and<exists $ref-{$key} >> is true, then$ref= $ref->{$key};is run [and this can't fail nor autovivify].Otherwise, Dive() returns an empty list and DiveError() can tell you where the problem was.
For DiveRef(),
$ref= $ref->{$key}is simply attempted. This may autovivify a hash entry or even a new hash. It may alsodie, for example, if $ref can't be used as a hash reference.
Note that the order of the above items is significant. It represents the order in which cases are tested. So an undefined $key will only be for derefencing a scalar reference and a numeric key will prefer to treat a reference as an array reference.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 274:
'=item' outside of any '=over'