But careful with mixed data structures and the risk of accidental symbolic references. strict can catch that.
An example:
my %hash;
$hash{beta} = 'x';
for my $name ( qw(alpha beta) ) {
push @{$hash{$name}}, 123, 456;
}
use Data::Dumper;
print Dumper \%hash;
Result:
$VAR1 = {
'alpha' => [
123,
456
],
'beta' => 'x'
};
So... where's the array data for 'beta'? It's in the global variable @x. Witness: append this line to the above script:
print Dumper \@x;
Result:
$VAR1 = [
123,
456
];
With strict enabled, it'll get caught while trying to push the data: insert the line use strict;
at the top of the script and comment out the line, dumping @x, we appended earlier:
Can't use string ("x") as an ARRAY ref while "strict refs" in use at t
+est.pl line 6.
Nasty if you didn't expect it.
The risk of running into it is greatest when using data structures of unequal depth.
|