put dx.pl into an explicit handle sub
[spider.git] / perl / export_opernam.pl
1 #!/usr/bin/env perl
2 #
3 # export a standard ak1a opernam.dat file into CSV format.
4 #
5 # Copyright (c) 1999 Dirk Koopman G1TLH
6 #
7 #
8
9 sub export
10 {
11         my $rec = shift;
12         my @f = unpack "SA13A23SA12A6SSSSA1CSSSA1A80A1A13A1", $rec;
13         my $f;
14
15         # clean each field
16         for $f (@f) {
17                 my @a = split m{\0}, $f;
18                 $f = $a[0] if @a > 1;
19         }
20
21         print join '|', @f;
22         print "\n";
23 }
24
25 die "Need an filename" unless @ARGV;
26 open IN, $ARGV[0] or die "can't open $ARGV[0] ($!)";
27
28 while (sysread(IN, $buf, 196)) {
29         export($buf);
30 }
31 close IN;
32 exit(0);