- 1.first do you meaning  values(%{$a})  as same as values($a) which $a
   is  references starting from perl-5.14 .

2. i did not know why  I compare two lists ? values($a) return the value of
hash which has only one element. so i just think  values($a)  return a list
just when $a has more than one element.
 and i modify  this to below
------------------------code
begin-----------------------------------------------------------
perl -e '
  @AoH = (
    (
       rsh => "0.4",
    ),
    (
       telnet=> "0.022",
    ),

    (
       ssh => "0.3",
    ),
  );
  print values($_) for sort my_sort @AoH; sub my_sort {
values($a)<=>values($b)}
'
------------------------code
end-----------------------------------------------------------
the error is ” Type of argument to values on reference must be unblessed
hashref or arrayref at -e line 15.“
i did not know why .
IMO  $a is a hash not a hash reference。it  Iteration values   ( rsh =>
"0.4",) which values will return 0.4, and another.
can you tell me the reason !

thank your very mush!

2012/7/5 Shlomi Fish <shlo...@shlomifish.org>

> Hi xiyoulaoyuanjia,
>
> On Thu, 5 Jul 2012 22:53:03 +0800
> xiyoulaoyuanjia <xiyoulaoyuan...@gmail.com> wrote:
>
> > hi:
> >
> > i want sort my array .but the result is not right. i did not know   why ?
> >
> > ---------------------------------------begin
> > code----------------------------------------------
> > perl -e '
> >
> > @AoH = (
> >     {
> >        rsh => "0.4",
> >     },
> >     {
> >        telnet=> "0.022",
> >     },
> >
> >     {
> >        ssh => "0.3",
> >     },
> >   );
> >   print values($_) for sort my_sort @AoH; sub my_sort {
> > values($a)<=>values($b)}
>
> First of all, one should note that values will only work on scalars
> (containing hash references) starting from perl-5.14. If you want
> compatibility
> with older Perl use values(%$a).
>
> Now what your comparison do is numerically compare two lists, which are
> also of
> equal length, so you get meaningless results.
>
> Another note is that generally an array of hashes should be of
> homogeneous items, so they can be processed identically. Don't put
> different
> keys in different hash - use the same keys.
>
> Regards,
>
>         Shlomi Fish
>
> > '
> > ----------------------------------end
> > code---------------------------------------------------------
> >
> > the result is 0.40.0220.3  apparently it did not right!
> >
> > after i  modify my_sort to this
> > sub my_sort { (values($a))[0]<=>(values($b))[0]}
> > it can work well ..
> >
> > anyone can tell me the reason!
> >
> > tanks!
> >
>
>
>
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> My Aphorisms - http://www.shlomifish.org/humour.html
>
> “We’re not doing it for money… we’re doing it for a shitload of money!”
>     ― Spaceballs, http://www.imdb.com/title/tt0094012/
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
继续上路。。

Reply via email to