Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Moritz Lenz
On 07/03/2015 10:02 PM, yary wrote: > On Fri, Jul 3, 2015 at 3:03 PM, Timo Paulssen wrote: >> but this does not >> >>> sub takes_int_array(Int @bar) { say @bar } >>> takes_int_array([1, 2, 3]) >> >> because the type match is against the defined type. We do not >> automatically infer that [1, 2,

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Timo Paulssen
On 07/03/2015 10:02 PM, yary wrote: > On Fri, Jul 3, 2015 at 3:03 PM, Timo Paulssen wrote: >> but this does not >> >>> sub takes_int_array(Int @bar) { say @bar } >>> takes_int_array([1, 2, 3]) >> because the type match is against the defined type. We do not >> automatically infer that [1, 2, 3] co

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread yary
On Fri, Jul 3, 2015 at 3:03 PM, Timo Paulssen wrote: > but this does not > >> sub takes_int_array(Int @bar) { say @bar } >> takes_int_array([1, 2, 3]) > > because the type match is against the defined type. We do not > automatically infer that [1, 2, 3] could be a Positional[Int]. How would one c

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Tom Browder
On Fri, Jul 3, 2015 at 2:03 PM, Timo Paulssen wrote: > On 07/03/2015 07:20 PM, Tom Browder wrote: >> On Fri, Jul 3, 2015 at 10:26 AM, Tom Browder wrote: ... >> What is the proper type to use for the %hash for a more complete >> signature in function foo1? I've tried various types such ... > When

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Timo Paulssen
On 07/03/2015 07:20 PM, Tom Browder wrote: > On Fri, Jul 3, 2015 at 10:26 AM, Tom Browder wrote: >> While experimenting I've found the first two methods of passing a hash >> to a subroutine work: >> >> # method 1 >> my %hash1; >> foo1(%hash1); >> say %hash1.perl; >> sub foo1(%hash) { >> %hash{1}

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Tom Browder
On Fri, Jul 3, 2015 at 10:26 AM, Tom Browder wrote: > While experimenting I've found the first two methods of passing a hash > to a subroutine work: > > # method 1 > my %hash1; > foo1(%hash1); > say %hash1.perl; > sub foo1(%hash) { > %hash{1} = 0; > } Another question on method 1 above, please:

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Tom Browder
On Jul 3, 2015 11:14 AM, "Brandon Allbery" wrote: > > On Fri, Jul 3, 2015 at 11:26 AM, Tom Browder wrote: >> >> # method 1 ... >> foo1(%hash1); > This is what I would naïvely expect to work in any language except Perl 5. That comment, along with Liz's, has convinced me to use method 1 (less typi

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Brandon Allbery
On Fri, Jul 3, 2015 at 11:26 AM, Tom Browder wrote: > # method 1 > my %hash1; > foo1(%hash1); > say %hash1.perl; > sub foo1(%hash) { > %hash{1} = 0; > } > This is what I would naïvely expect to work in any language except Perl 5. > # method 2 > my %hash2; > my $href2 = %hash2; > foo2($href2)

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Elizabeth Mattijsen
> On 03 Jul 2015, at 17:26, Tom Browder wrote: > > While experimenting I've found the first two methods of passing a hash > to a subroutine work: > > # method 1 > my %hash1; > foo1(%hash1); > say %hash1.perl; > sub foo1(%hash) { > %hash{1} = 0; > } > > # method 2 > my %hash2; > my $href2 = %ha

Passing a hash to a subroutine: best method?

2015-07-03 Thread Tom Browder
While experimenting I've found the first two methods of passing a hash to a subroutine work: # method 1 my %hash1; foo1(%hash1); say %hash1.perl; sub foo1(%hash) { %hash{1} = 0; } # method 2 my %hash2; my $href2 = %hash2; foo2($href2); say %hash2.perl; sub foo2($href) { $href{1} = 0; } # thi