title: Perl sorting an array of references to arrays
body: <p>I am relatively new to Perl.  I have a reference to an array called $TransRef that contains references to arrays.  My goal is to write a sub that takes the $TransRef arguement as its only argument, sorts the references to the underlying array by the 2nd element (a string) and sets the output back to the $TransRef reference.  Can someone please show how this can be done in Perl?</p>
  
  <p>Here is some code that generates $TransRef.  It has not been tested yet and may have some bugs:</p>
  
  <pre><code># Parse the data and move it into the Transactions container.
  for ($Loop = 0; $Loop &lt; 5; $Loop++)
  {
     $Line = $LinesInFile[$Loop];
     # Create an array called Fields to hold each field in $Line.
     @Fields = split /$Delimitor/, $Line;  
     $TransID = $Fields[2];
     # Save a ref to the fields array in the transaction list.
     $FieldsRef = \@Fields;
     ValidateData($FieldsRef);
     $$TransRef[$Loop] = $FieldsRef;
  }
  SortByCustID($TransRef);
  
  sub SortByCustID()
  {
     # This sub sorts the arrays in $TransRef by the 2nd element, which is the cust #.
     # How to do this?
     my $TransRef = @_;
     ...
  }
  </code></pre>