develooper Front page | perl.perl6.language | Postings from April 2005

pass hash to sub expecting named params?

Thread Next
From:
Carl Franks
Date:
April 25, 2005 01:14
Subject:
pass hash to sub expecting named params?
Message ID:
4f352aae05042501144507f8ec@mail.gmail.com
Will it be valid to pass a hash to a subroutine expecting named
params, if the hash keys match the names?

sub do_this (+$foo, +$bar) {
  # whatever
}

%arg = (
  :foo,
  :bar,
);

do_this(*%arg);

I use this technique a lot, and it would be unfortunate to miss out on
the advantages of subroutine signatures and have to 'go back' to the
perl5-ish
sub do_this (*%args) { }

Carl Franks

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About