Subject: | Another way of obtaining "Modification of non-creatable array value attempted, subscript -1" |
Similar to the previous bug: if you hoe into @_ directly, Bad Things happen when you try to display the returned value:
I have a patch that allows Devel::TraceSubs to survive such trickery, but at the expense of making the return args look is if they were stored in an array reference. Which would be definitely misleading.
__BEGIN__
#! /usr/local/bin/perl -w
use strict;
sub hashref_offset {
my $nr = @{$_[0]};
my $pos = -1;
ref($_[0]->[$pos]) eq 'HASH' and return $pos while ++$pos < $nr;
return -1;
}
use Devel::TraceSubs;
my $dbg = Devel::TraceSubs->new( params => shift || 0 )->trace( 'main::' );
print hashref_offset( [1, 2, 3] ), "\n"; # prints -1 (no hashref)
print hashref_offset( [4, 5, {6=>6}] ), "\n"; # prints 2 (hashref at offset 2)