I like this idea in theory, it’s come up several times now.
I'm a little unclear how doing this at the core subroutine level is different/better than just doing it with a hash:
sub color($x) {
my $red = $x->{red} // 0;
my $green = $x->{green} // 0;
my $blue = $x->{blue} // 0;
...
}
That syntax has worked forever. If it’s in core we could enforce defaults and types easier I suppose, but I don’t know if that’s a big enough benefit.
- scottchiefbaker
I like this idea in theory, it’s come up several times now.
I'm a little unclear how doing this at the core subroutine level is different/better than just doing it with a hash:
sub color($x) { my $red = $x->{red} // 0; my $green = $x->{green} // 0; my $blue = $x->{blue} // 0; ... }
That syntax has worked forever. If it’s in core we could enforce defaults and types easier I suppose, but I don’t know if that’s a big enough benefit.
sub color($x) { my $red = delete $x->{red} // die "Missing red value"; my $green = delete $x->{green} // die "Missing green value"; my $blue = delete $x->{blue} // die "Missing blue value"; if ($x->%*) { die "Unknown parameters ...."; } ... }
As opposed to simplysub color(:$red, :$green, :$blue) { ... }
I know what I prefer. HTH, M4