Google Groups Home
Help | Sign in
pass hash to sub expecting named params?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Luke Palmer  
View profile
 More options Apr 25 2005, 4:29 am
Newsgroups: perl.perl6.language
From: l...@luqui.org (Luke Palmer)
Date: Mon, 25 Apr 2005 02:29:48 -0600
Local: Mon, Apr 25 2005 4:29 am
Subject: Re: pass hash to sub expecting named params?

Carl Franks writes:
> 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);

Yep, and that's exactly how you do it, too.  I believe that the * is
unnecessary (but still acceptable) if you're already in the named zone:

    do_this(foo => 1, %arg);  # ok

Luke


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl Franks  
View profile
 More options Apr 25 2005, 4:14 am
Newsgroups: perl.perl6.language
From: fireart...@gmail.com (Carl Franks)
Date: Mon, 25 Apr 2005 09:14:31 +0100
Local: Mon, Apr 25 2005 4:14 am
Subject: pass hash to sub expecting named params?
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl Franks  
View profile
 More options Apr 25 2005, 4:50 am
Newsgroups: perl.perl6.language
From: fireart...@gmail.com (Carl Franks)
Date: Mon, 25 Apr 2005 09:50:49 +0100
Local: Mon, Apr 25 2005 4:50 am
Subject: Re: pass hash to sub expecting named params?
That puts my mind at ease!
Many thanks,

Carl

On 4/25/05, Luke Palmer <l...@luqui.org> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google