Re: Hash return value

2006-03-17 Thread Chris Wagner
Yeah that's what I started to suspect after I posted. mkhash() should be saved to a variable name and that variable used in the while each loop. At 01:18 PM 3/18/2006 +1100, Sisyphus wrote: >That's not what I find. >The following script (suggested by Chris) simply prints "All done" for me. > my

Re: Hash return value

2006-03-17 Thread Sisyphus
- Original Message - From: "Eric Amick" . . > You can return a reference to a > hash instead and then dereference it in the caller: > > while (($key, $value)= each( %{ mkhash() })) > { > print("$key = $value\n"); > } > > sub mkhash > { > my %hash=('one'=>1, 'two'=>2, 'three'=>3);

Re: Hash return value

2006-03-17 Thread Eric Amick
On Fri, 17 Mar 2006 12:05:07 -0800, you wrote: ># Using subroutine that returns a hash doesn't work >while (($key, $value)= each( mkhash() )) >{ >print("$key = $value\n"); >} > >sub mkhash >{ > my %hash=('one'=>1, 'two'=>2, 'three'=>3); > return %hash; >} The each() function expects i

Re: Hash return value

2006-03-17 Thread Chris Wagner
At 04:40 PM 3/16/2006 -0700, Edwards, Mark (CXO) wrote: >The each function requires a hash as an argument. I would think that a >subroutine that returns a hash could be used as the argument, but it >doesn't work. Why? Is my syntax wrong or is that just the way Larry >made it? U have to evaluate

Re: Hash return value

2006-03-16 Thread Sisyphus
- Original Message - From: "Edwards, Mark (CXO)" . . > # Using subroutine that returns a hash doesn't work > while (($key, $value)= each( mkhash() )) One problem with allowing that is that at each iteration of the while loop, mkhash() gets re-run, returning another anonymous hash. The ea

Hash return value

2006-03-16 Thread Edwards, Mark (CXO)
The each function requires a hash as an argument. I would think that a subroutine that returns a hash could be used as the argument, but it doesn't work. Why? Is my syntax wrong or is that just the way Larry made it? use warnings; use strict; my ($key, $value, %hash) ; # Using hash for funct