Regex fix was a bug; this undoes it
[migration-tools.git] / unicorn / unicorn_patrons_to_lostitem_tsv.pl
1 #!/usr/bin/perl -w
2
3 # Converts a Unicorn users.data file to a tab-separated file of lost items.
4 # 2009-11-06 Ben Ostrowsky <ben@esilibrary.com>
5 #
6 # Output fields:
7 #
8 #   Patron ID
9 #   Item ID
10 #   Item Copy Number
11 #   Due Date
12 #   Title, Author, Call (or parts thereof)
13 #
14
15 my $field = '';
16 my $lostitem = '';
17 my $userid = '';
18
19 # Load each record
20 while (<>) {
21     s/\r\n/\n/g;
22 # print STDERR "Loaded this line: " . $_;
23
24         if ( /^\.(.*?).\s+(\|a)?(.*)$/ ) {
25                 $field = $1;
26                 if ($field eq 'USER_ID') { 
27                         if ($lostitem ne '') { 
28                                 $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
29                                 print "$userid\t$3\t$2\t$4\t$1\n"; 
30                         }
31                         $userid = $3;
32                         $lostitem = '';
33                 }
34                 if ($field eq 'LOSTITEM') { 
35                         if ($lostitem ne '') { 
36                                 $lostitem =~ m/^(.*)copy:([^,]*),\s*ID:([^,]*),\s*due:(.*)$/;
37                                 print "$userid\t$3\t$2\t$4\t$1\n"; 
38                         }
39                         $lostitem = $3;
40                 } 
41                 next;
42         }       
43
44         # This is the continuation of the previous line.
45         else {
46                 chomp($_);
47                 if ($field eq 'LOSTITEM') { $lostitem .= $_; }
48         }
49
50 }