[BACK]Return to pta_import.pl CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / pta

Diff for /pta/pta_import.pl between version 1.13 and 1.14

version 1.13, 2020/11/18 21:32:16 version 1.14, 2020/11/18 22:25:05
Line 118  sub usage () {
Line 118  sub usage () {
   
 # === MAIN PROGRAM =====================================================  # === MAIN PROGRAM =====================================================
   
 my ($csv_account, $fn, $in, $account_name, $delim, @compiled);  
   
 # Parse command line arguments.  
 getopts 'I:' or usage;  getopts 'I:' or usage;
 if ($opt_I) {  unless ($opt_I) {
         $account_name = $opt_I;          warn "The option -I is required.";
         $banks{$account_name} or die "unknown accountname: $account_name";  
         $fn = "import_" . $account_name . ".txt";  
         open $in, $fn or die "$fn: $!";  
 } else {  
         usage;          usage;
 }  }
   my $account_name = $opt_I;
   $banks{$account_name} or die "unknown accountname: $account_name";
   
 # Parse the configuration file.  # Parse the configuration file.
   my $fn = "import_" . $account_name . ".txt";
   open my $in, '<', $fn or die "$fn: $!";
   my ($csv_account, $delim, $header, @compiled);
 while (<$in>) {  while (<$in>) {
         chomp;          chomp;
         next if /^(?:#|$)/;          next if /^(?:#|$)/;
Line 146  while (<$in>) {
Line 144  while (<$in>) {
                 $delim = $1;                  $delim = $1;
                 next;                  next;
         }          }
           if (/^HEADER\s+(.*)$/) {
                   $header and die "duplicate HEADER line: $1";
                   $header = $1;
                   next;
           }
         $delim or die "no DELIM line in $fn";          $delim or die "no DELIM line in $fn";
         s/^(.*)$delim\s+(\d+)\s+(\S+)// or          s/^(.*)$delim\s+(\d+)\s+(\S+)// or
             die "$fn import parse error: $line";              die "$fn import parse error: $line";
Line 159  close $in;
Line 162  close $in;
 $csv_account or die "no ACCOUNT line in $fn";  $csv_account or die "no ACCOUNT line in $fn";
   
 # Parse the CSV file from the bank.  # Parse the CSV file from the bank.
 chomp(my $header = <>);  
 while (<>) {  while (<>) {
         chomp;          chomp;
         next if (/^$/);          next if (/^$/);
         my $line = $_;          my $line = $_;
           if ($header) {
                   $line eq $header
                       or die "expected HEADER $header\nbut got $line";
                   undef $header;
                   next;
           }
         my @fields = split /$delim/, $line;          my @fields = split /$delim/, $line;
         my $matches = 0;          my $matches = 0;
         my ($account, $booking);          my ($account, $booking);

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

CVSweb