p5pclub / ref-util

Ref::Util - Utility functions for checking references
6 stars 11 forks source link

Modification of non-creatable array value attempted, subscript -1 #46

Open karenetheridge opened 3 years ago

karenetheridge commented 3 years ago
$; perl -MRef::Util=is_arrayref -wle'my @a = (); print $a[-1]; print is_arrayref($a[-1])'
Use of uninitialized value in print at -e line 1.

Modification of non-creatable array value attempted, subscript -1 at -e line 1.

This only happens with perls earlier than 5.20.

The problem is not simply with sub arguments:

$; perl -wle'my @a = (); print $a[-1]; sub foo { my (@args) = @_; print $args[-1] }  foo();'
Use of uninitialized value in print at -e line 1.

Use of uninitialized value in print at -e line 1.
haarg commented 3 years ago

This is a problem with all subs.

$ perl -e'my @a = (); sub foo {} foo($a[-1]);'
Modification of non-creatable array value attempted, subscript -1 at -e line 1.