First of all, I concede that features like autovivification and
undefs defaulting to the domain-qualified 'none' are fine as what
Perl does by default, so I retract any request to change this; I am
fine for these things to remain as they are and were.
-- Darren Duncan
P.S. FYI, permit me to illustrate here that alternatives to
autovivification are not as laborous as they can be made out to be.
At 1:49 PM -0600 12/19/05, Rod Adams wrote (off-list):
That makes histograms, which I use constantly, a major pain in the rump.
my @x;
# something which fills @x
my %x;
for @x { %x{$_}++ }
that last line becomes
for @x {
if defined(%x{$_}) {
%x{$_}++;
} else {
%x{$_} = 1;
}
}
There is a much more concise, but still explicit solution, which is
what I do in these situations. Instead of:
my %x;
for @x {
%x{$_}++;
}
You have:
my %x;
for @x {
%x{$_} //= 0;
%x{$_}++;
}
The number of code lines increases linearly by depth, with one line
added per nest level, and not by orders of magnitude such as the
doubling that your if/else would suggest.
It gets even worse when you consider something like:
my %data;
for =$File -> $line {
my ($x, $y, $z) = $line.split;
%data{$x}{$y}{$z}++;
}
Considering that Perl 6 has multi-dimensional hash keys, you may only
need something like this instead of the last line anyway:
%data{$x;$y;$z} //= 0;
%data{$x;$y;$z}++;
But even if you do this the older way, that last line would become only:
%data{$x} //= hash();
%data{$x}{$y} //= hash();
%data{$x}{$y}{$z} //= 0;
%data{$x}{$y}{$z}++;
-- Darren Duncan