3 ms·
> Is this [autovivification] always good? No. Good thing then that the programmer has the choice to use it or not. repl>>> no autovivification 'store'
by bmn__ 6y ago
> Is this [autovivification] always good? No.
Good thing then that the programmer has the choice to use it or not.
repl>>> no autovivification 'store'
repl>>> my %h
%h = ()
repl>>> $h{'foo'}[3]{'bar'} = 'bletch'
Runtime error: Can't vivify reference at (eval …)
> Is this [returning undef for non-existing keys/indexes] always good. […] the answer is no.
Good thing then that the programmer has the choice to use it or not.
repl>>> use Hash::Util 'lock_keys'
repl>>> my %h
%h = ()
repl>>> lock_keys %h
()
repl>>> $h{no_such_key}
Runtime error: Attempt to access disallowed key 'no_such_key' in a restricted hash at (eval …)
repl>>> package Array::Bounded {
use Tie::Array;
use base 'Tie::StdArray';
sub FETCH {
my ($self, $index) = @_;
die "Attempt to access out of bounds index $index in a restricted array" if $index >= $self->@*;
return $self->[$index];
}
}
repl>>> tie my @a, 'Array::Bounded'
repl>>> @a = ('a'..'f')
@a = ('a'..'f')
repl>>> $a[5]
f
repl>>> $a[6]
Runtime error: Attempt to access out of bounds index 6 in a restricted array at (eval …)