title: sort function definitions according to its size
body: <p>I am getting function definitions sizes from a .C file and I have list of all functions definitions names in a text file</p>
  
  <p>CODE</p>
  
  <pre><code>open(FILE, "&lt; file.c") or die $!;                #source file
  my @lines = &lt;FILE&gt;;
  close(FILE);
  
  open(FILE2, "&gt; file_function_size.txt") or die $!;
  
  open(FILE1, "&lt; functions.txt") or die $!;        #contains list of function names
  chomp( my @functions = &lt;FILE1&gt; );
  close(FILE1);
  
  my $match_function = qr/\b(@{[ join '|', map quotemeta, sort { length($b) &lt;=&gt; length($a) } @functions ]})\([^;]+$/;
  my %function_size;
  my $function = '';
  for my $source_line (@lines) {
      if ( $source_line =~ $match_function ) {
          $function = $1;
          $function_size{$function} = 0;
      }
      elsif ( $source_line =~ /^}/ ) {
          $function = '';
      }
      # ignore first {
      elsif ( $function &amp;&amp; ( $source_line !~ /^{/ || $function_size{$function} ) ) {
          ++$function_size{$function};
      }
  }
  
  for my $function (@functions) {
      if ( exists $function_size{$function} ) {
          print FILE2 "Function $function has $function_size{$function} lines.\n";
      }
  }
  </code></pre>
  
  <p>OUTPUT I GET IS </p>
  
  <pre><code>Function ChainCtrlBuildChain has 63 lines.
  Function ChainCtrlDumpChain has 22 lines.
  Function ChainCtrlExit has 6 lines.
  Function ChainCtrlGetBitStreamChan has 36 lines.
  </code></pre>
  
  <p><strong>I want to sort it according to its size</strong></p>
  
  <pre><code>Function ChainCtrlExit has 6 lines.
  Function ChainCtrlDumpChain has 22 lines.
  Function ChainCtrlGetBitStreamChan has 36 lines.
  Function ChainCtrlBuildChain has 63 lines.
  </code></pre>