seouri (owner)

Revisions

gist: 83732 Download_button fork
public
Public Clone URL: git://gist.github.com/83732.git
Embed All Files: show embed
read_savedrecs.pl #
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
sub read_savedrecs {
  my $dir = shift;
  my (@rec, @head);
  foreach my $f (<$dir/savedrecs*.txt>) {
    my @file = read_file($f);
    my $head = shift @file;
    @head = @$head unless $#head > 0;
    push @rec, @file;
  }
  my %head_idx;
  for (my $i = 0; $i <= $#head; $i++) {
    $head_idx{$head[$i]} = $i;
  }
  my %tag = tag($dir);
  print STDERR join("\n", map { "[" . $head_idx{$_} . "] $_: " . ($tag{$_} || "U
NKNOWN COLUMN")} sort { $head_idx{$a} <=> $head_idx{$b} } keys %head_idx), "\n";
  print STDERR scalar(@rec), " records\n";
  return (\%head_idx, @rec);
}
 
sub tag {
  my $dir = shift;
  my @file = read_file("$dir/tags.dat");
  my %tag;
  foreach my $f (@file) {
    my ($tag, $description) = @$f;
    $tag{$tag} = $description;
  }
  return %tag;
}
 
sub read_file {
  my $file = shift;
  print STDERR "READ $file ... ";
  my @file;
  open(FH, "< $file") or die("Can't read $file: $!\n");
  while (<FH>) {
    chomp;
    my @t = split /\t/;
    @t = map { s/^\s+//g; s/\s+$//g; $_ } @t;
    push @file, \@t;
  }
  close FH;
  print STDERR scalar(@file), " lines\n";
  return @file;
}