| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use Modern::Perl; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use autodie qw(:all); | ||
| 7 | no indirect ':fatal'; | ||
| 8 | |||
| 9 | use Carp; | ||
| 10 | |||
| 11 | use TSQL::FlatFile; | ||
| 12 | use Text::CSV ; | ||
| 13 | use Readonly ; | ||
| 14 | use List::MoreUtils qw(any) ; | ||
| 15 | |||
| 16 | use File::Basename; | ||
| 17 | use Smart::Comments; | ||
| 18 | use Try::Tiny; | ||
| 19 | |||
| 20 | use Getopt::Euclid qw( :vars<opt_> ); | ||
| 21 | use List::MoreUtils qw{firstidx} ; | ||
| 22 | use Data::Dumper; | ||
| 23 | use Regexp::Exhaustive qw/ exhaustive /; | ||
| 24 | |||
| 25 | use version ; our $VERSION = qv('1.0.2'); | ||
| 26 | our $opt_asciifile; | ||
| 27 | our $opt_csvfile; | ||
| 28 | our $opt_linenumber; | ||
| 29 | our $opt_datalinenumber; | ||
| 30 | our $opt_nodebug; | ||
| 31 | our $opt_nodatadebug; | ||
| 32 | our $opt_noincrementalsearch; | ||
| 33 | |||
| 34 | use Text::CSV; | ||
| 35 | |||
| 36 | my $csvfile = $opt_csvfile; | ||
| 37 | my $asciifile = $opt_asciifile; | ||
| 38 | my $linenumber = $opt_linenumber; | ||
| 39 | my $datalinenumber = $opt_datalinenumber; | ||
| 40 | my $debug = defined($opt_nodebug) ? !$opt_nodebug : 0; | ||
| 41 | my $datadebug = defined($opt_nodatadebug) ? !$opt_nodatadebug : 0; | ||
| 42 | my $incrementalsearch = defined($opt_noincrementalsearch) ? !$opt_noincrementalsearch : 0; | ||
| 43 | |||
| 44 | my $obj = TSQL::FlatFile->new(); | ||
| 45 | |||
| 46 | my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1 }); | ||
| 47 | open my $fh, "<:encoding(utf8)", $csvfile or die "csvfile: $!"; | ||
| 48 | |||
| 49 | if ($datadebug) | ||
| 50 | { | ||
| 51 | my $res = $obj->getLinePositions | ||
| 52 | ( $asciifile | ||
| 53 | , $csv | ||
| 54 | , $fh | ||
| 55 | , $linenumber | ||
| 56 | , $incrementalsearch | ||
| 57 | ) ; | ||
| 58 | say "best_line:",$$res->{best_line}; | ||
| 59 | say "best_unmatchedcount:",$$res->{best_unmatchedcount}; | ||
| 60 | say "best_unmatchedamount:",$$res->{best_unmatchedamount}; | ||
| 61 | |||
| 62 | $obj->printDebugData | ||
| 63 | ( $asciifile | ||
| 64 | , $datalinenumber | ||
| 65 | , $$res->{positions} | ||
| 66 | ); | ||
| 67 | |||
| 68 | } | ||
| 69 | else { | ||
| 70 | my $res = $obj->processLine | ||
| 71 | ( $asciifile | ||
| 72 | , $csv | ||
| 73 | , $fh | ||
| 74 | , $linenumber | ||
| 75 | , $incrementalsearch | ||
| 76 | , $debug | ||
| 77 | ) ; | ||
| 78 | say $res; | ||
| 79 | } | ||
| 80 | |||
| 81 | close $fh; | ||
| 82 | |||
| 83 | exit ; | ||
| 84 | |||
| 85 | # ####################################################################################### | ||
| 86 | |||
| 87 | |||
| 88 | END { | ||
| 89 | } | ||
| 90 | |||
| 91 | __DATA__ |