in reply to Re^2: passing array ref without variable
in thread passing array ref without variable

I suppose what you really want/need is to pass the hash as reference, like this you don't need to pass the values and the keys separately.

 call(\%hash)

If you explicitly want to pass the reference of a copy do this

 call( { %hash } )

the { ... } returns a ref of an anonymous hash of the list expanded from %hash, i.e. the ref of a hashcopy!

Cheers Rolf

Replies are listed 'Best First'.
Re^4: passing array ref without variable
by vit (Friar) on May 03, 2010 at 21:07 UTC
    No I do not want to pass a hash. What I want to do is having a hash ($h{key} = value) and
    sub my_function { my $arr_ref = shift; ... }
    I can pass keys as an array ref by
    my_function([keys %hash])
    Now, I want to pass values as an array ref in a shortest way without forming an array. Is it possible?
      Hmmm.

      You know that you get the keys of a hash using a function called keys.

      What do you think would be the name of the function that returns the values of a hash?

      Is it possible?

      Short answer, yes!

       my_function([values %hash])

      but please be aware that this is only a flat copy.

      Cheers Rolf

        what is a "flat copy?"