Thursday, January 02, 2020

Re: perl popularity inside openbsd community? (Re: Suggestion: Replace Perl ...)

On Thu, Jan 02, 2020 at 02:40:25PM -0600, danieljboyd@icloud.com wrote:
> What if you want named parameters? (i.e. sending a hash as your
> argument)
>
> sub m4
> {
> my $self = shift;
> my %args = @_;
>
> # and then optionally
> my ($arg1, $arg2, $arg3) = @args{qw/arg1 arg2 arg3/};
>
> # or you can just use $args{arg1}, etc...
> }

Such cases are a refactoring waiting to happen. If your parameters
get complicated enough that you want to name them, these's usually an
object hiding in there :)

No comments:

Post a Comment