File: sort2.pl

package info (click to toggle)
gnutls13 1.4.4-3%2Betch5
  • links: PTS
  • area: main
  • in suites: etch
  • size: 24,052 kB
  • ctags: 12,507
  • sloc: ansic: 94,474; xml: 17,016; sh: 9,652; perl: 628; makefile: 607; sed: 16
file content (25 lines) | stat: -rwxr-xr-x 576 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl

sub key_of_record {
  local($record) = @_;

  # Split record into lines:
  my @lines = split /\n/, $record;

  my ($i) = 1;
  my ($key) = $lines[$i];

  while( !($key =~ /^\@deftypefun/) && ($i < 5)) { $i=$i+1; $key = $lines[$i]; }

  $key = $1 if $key =~ /^\@deftypefun {.*} {(.*)}/;

#  print STDERR "key $1\n";

  return $key;
}

$/="@end deftypefun";          # Records are separated by blank lines.
@records = <>;  # Read in whole file, one record per array element.

@records = sort { key_of_record($a) cmp key_of_record($b) } @records;
print @records;