Whenever you get errors or warnings, I suggest you look up the perldiag manual page to see more verbose explanation. Or, you can put the use diagnostics; line near the top of your program. This way, you let Perl explains more detail about what's wrong or what might be wrong in your program. The first is really a warning message instead of an error (indicated by "(W)", while the second is a fatal error.
Use of reference "%s" as array index (W misc) You tried to use a reference as an array index; this probab +ly isn't what you mean, because references in numerical context tend to + be huge numbers, and so usually indicates programmer error. If you really do mean it, explicitly numify your reference, like so: $array[0+$ref]. This warning is not given for overloaded objects, either, because you can overload the numifi- cation and stringificat +ion operators and then you assumedly know what you are doing. Can't call method "%s" on unblessed reference (F) A method call must know in what package it's supposed to run. I +t ordinarily finds this out from the object reference you supply, but +you didn't supply an object reference in this case. A reference isn't a +n object reference until it has been blessed. See per- lobj.
The @unsorted array contains list of objects of GARD::Book class, when you pass it to the sort function, the $a and $b variables contain references to the correspondent elements in that array. So you simply say $a->function instead of $unsorted[$a]->function in the sort block.

Saying $a->function in the sort block is the same with $unsorted[SOME_INDEX]->function outside the block. When you say $unsorted[$a]->function in the sort block the following (more or less) happens:


Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: sorting an array of objects (surely it should be easy!) by naikonta
in thread sorting an array of objects (surely it should be easy!) by jfrm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.