in reply to Using $# defines a variable?
Short answer: autovivification.
When you write $#{$array}, you're asking Perl what the last index of the array is which the reference $array points to, in other words, you're using the previously undefined $array like an array reference, so Perl autovivifies an anonymous array for you. See also item 3 under Using References.
use warnings; use strict; use Data::Dumper; my $array; print Dumper($array); print Dumper($#{$array}); print Dumper($array); __END__ $VAR1 = undef; $VAR1 = -1; $VAR1 = [];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using $# defines a variable?
by LanX (Saint) on May 18, 2019 at 22:14 UTC |