sub mapat { my $depth = shift; my $f = shift; $depth ? map [ map mapat($depth-1, $f, $_), @$_ ], @_ : $f->(@_); }