In the following code:
use strict;
use warnings;
use Data::Dumper;
my %hash = %Whatever::whatever;
my @array = @Whatever::whatever;
print Dumper \@array;
print Dumper \%hash;
My understanding is that @Whatever::whatever is accessing the symbol table, and doesn't produce an error message because symbol table is a hash. But why there isn't at least a warning message for accessing a non-existing element?
Because it's almost impossible to catch a global variable in a state of non-existence in Perl. As soon as you mention one by name — even just to take a reference to it — it exists. And because arrays and hashes are different from scalars; a scalar comes into existence holding the value undef
, which triggers a "use of uninitialized value" warning when used for most purposes; but arrays and hashes come into existence as empty arrays and hashes, and an empty array or hash isn't exceptional enough to warn about!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With