Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am not sure if this is possible but I have the code:
my @temparr = values %arr; my $mean_of_arr = &average(\@temparr);
I would like to be able to not create the @temparr, if its possible and just do something like:
my $mean_of_arr = &average(\@{values %arr});
but obviously that doesn't work.

Replies are listed 'Best First'.
Re: passing the reference of hash values array
by LanX (Saint) on Nov 17, 2010 at 02:03 UTC
    I think you want:

     my $mean_of_arr = &average( [ values %arr ] );

    [LIST] creates an anonymous array ref.

    but why do you use this old function &call syntax?

    Cheers Rolf

      yep the brackets worked. thanks : ) Is it better to just use 'average(...)"? I just use the & since it gets highlighted/colorcoded for syntax whereas without the & its just plain black text.
        yes, IIRC it bypasses some mechanisms like prototype checking ...

        which editor do you use?

        Cheers Rolf

Re: passing the reference of hash values array
by PeterPeiGuo (Hermit) on Nov 17, 2010 at 02:07 UTC
    use Data::Dumper; use strict; use warnings; my %arr = (1,2,3,4,5,6); print Dumper([values(%arr)]);

    Peter (Guo) Pei

Re: passing the reference of hash values array
by roboticus (Chancellor) on Nov 17, 2010 at 02:03 UTC