seouri (owner)

Revisions

gist: 63949 Download_button fork
public
Public Clone URL: git://gist.github.com/63949.git
Embed All Files: show embed
read_bin.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
sub read_bin {
  my $file = shift;
  print STDERR "READ $file ... ";
  open(FH, "< $file") or die("Can't open $file: $!\n");;
  my @bin = <FH>;
  close FH;
  my $bin = join("", @bin);
  my @record = split /\*NEWRECORD\s+/s, $bin;
  my @file;
  foreach my $r (@record) {
    if ($r) {
      my @field = split /\n/, $r;
      my %record;
      foreach my $f (@field) {
        my ($key, $val) = split /\s*=\s*/, $f, 2;
        $key =~ s/^\s+//g;
        $val =~ s/\s+$//g;
        push @{$record{$key}}, $val;
      }
      push @file, \%record if $record{RECTYPE} && $record{RECTYPE}->[0] eq "D";
    }
  }
  print STDERR scalar(@file), " records\n";
  return @file;
}