in reply to Using $# defines a variable?
Hello smittypaddler,
Some notes:
- Obligatory reference on autovivification: Autovivification: What is it and why do I care? by Uri Guttman
- $#{$array} can be written more simply without the braces: $#$array
- The CPAN module autovivification can be used to disable this behaviour:
use strict;
use warnings;
no autovivification;
my $array;
warn sprintf 'array is%s defined', defined $array ? '' : ' not';
warn '$#$array is ', $#$array;
warn sprintf 'array is%s defined', defined $array ? '' : ' not';
Output:
13:28 >perl 1999_SoPW.pl
array is not defined at 1999_SoPW.pl line 7.
Can't use an undefined value as an ARRAY reference at 1999_SoPW.pl lin
+e 8.
13:28 >
Hope that’s of interest,
|