change to the data directly automatically with mig env use
[migration-tools.git] / mandarin / clean_mandarin_loan_list_report.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # copy and paste raw text from acrobat reader to .txt file
7
8 my $filename = $ARGV[0];
9 open(my $fh, '<:encoding(UTF-8)', $filename)
10   or die "Could not open file '$filename' $!";
11
12 my $user;
13  
14 while (my $row = <$fh>) {
15   chomp $row;
16   if ($row =~ m/Items On Loan by Patron/) { next; }
17   if ($row =~ m/Patron Title Barcode /) { next; }
18   if ($row =~ m/Page: /) { next; }
19   if ($row =~ m/Program Files \(x86\)/) { next; }
20   if ($row =~ m/End Of Report/) { next; }
21
22   my @str = split / /, $row;
23   my $str_length = scalar(@str);
24   if ($str[1] eq 'AM' or $str[1] eq 'PM') {
25     if ($str[2] =~ m/2019/) { next; }   
26   }
27
28   if ($str[$str_length -1] !~ m/\d\d\/\d\d\/\d\d\d\d/) {
29     $user = $str[$str_length -1];
30     next;
31   }
32
33   #print "$row\n";
34   if ($str[$str_length -1] =~  m/\d\d\/\d\d\/\d\d\d\d/) {
35     my $due       = $str[$str_length -1];  
36     my $borrowed  = $str[$str_length -2];  
37     my $item      = $str[$str_length -3];  #item
38     print "$user\t$item\t$due\t$borrowed\n";
39   } 
40 }