title: Sort in an object
body: <p>I have an object ($p), and in the initialization I have <code>$this-&gt;{list} = [];</code></p>
  
  <p>Later, I fill up the array with objects of another class (q), and can access them as <code>@{$self{list}}</code> in another subroutine in class [p]. I am trying to sort this array, as</p>
  
  <pre><code>my @slist = sort $self-&gt;point_sort, @{$self-&gt;{list}};
  </code></pre>
  
  <p><code>point_sort</code> is defined as a subroutine in class p, and I am getting</p>
  
  <pre><code>Can't call method "getQval" on an undefined value at p.pm line 64
  </code></pre>
  
  <p><code>getQval</code> is a subroutine defined in object q, instances of which populate the <code>{list}</code>. I am trying to do</p>
  
  <pre><code>my $v1 = $a-&gt;getQval;
  my $v2 = $b-&gt;getQval;
  </code></pre>
  
  <p>in the subroutine <code>point_sort</code>. Any suggestions? TIA.</p>
  
  <p>Edit:
  Changed the call to</p>
  
  <pre><code>my @slist = sort { $self-&gt;point_sort ($a,$b) } @{$self-&gt;{list}};
  </code></pre>
  
  <p>In point_sort, I have now</p>
  
  <pre><code>my ($c, $d) = @_;
  my $val1 = $c-&gt;getVarVal;
  </code></pre>
  
  <p>The error: </p>
  
  <pre><code>Can't locate object method "getVarVal" via package "packageP" at ...
  </code></pre>
  
  <p>I think it has something to do with packages, not sure what it is. It is looking in package p, whereas I want it to look at package q.</p>
  
  <p>Edit:
  I did a <code>print</code> on <code>$c</code> above - perl thinks it is an object of class p - a hashtable</p>