This is not the same thing. You are sorting the objects themselves rather than a hash stored within an object.
This is a cheat because now $a and $b are object references, so they speak for themselves. If $a and $b are simply keys of a hash, the sort function has no clue to what object they belong.
However it is true, as others pointed out, that if I write the compare function in-line instead of a separate function, the in-line code sees the variables of the sub ( including the $self with which it was called ), so it has access to the object.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|