
KevinR
Veteran

Apr 9, 2009, 5:55 PM
Post #10 of 10
(395 views)
|
|
Re: [ccin1492] returning a hash from a subroutine...
[In reply to]
|
Can't Post
|
|
Actually, I am running with "strict", but it didn't complain. Then you must have declared $cap somewhere otherwise perl would have exited with an error. So I finally got it to work. Here's what I did: 1, changed $cap->{...} to $cap{...}, Like you said they are two different data structures, but I don't quite understand the subtleties. One is a hash and one is a reference to a hash, but not the same hash 2, changed "return $cap" to "return %cap", and I'm don't know what the first one returns, but I'm sure the second returns a hash. The first one returns the reference $cap, the second one does return the hash %cap but as a flattened list, that can be very important to understand. 3, changed $CAP_VAL[$num] t0 %{ $CAP_VAL[$num] }. This was the key. I'm not sure why, but the %{ } around the array made sure I captured the complete array. Without seeing more context that isn't helpful for me to know why that makes your code work. %{} is dereferencing $CAP_VAL[$num] into its hash form, but that needs to be assigned to something or used to loop over the hash, for example, this would make sense if $CAP_VAL[$num] is a reference to a hash: my %hash = %{$CAP_VAL[$num]}; Thanks for your help and time! You're welcome -------------------------------------------------
|