#!/usr/bin/env perl my $codepage = 'utf8'; use utf8; binmode(STDOUT, ":$codepage"); binmode(STDOIN, ":$codepage"); use Text::CSV; #get file names: my $fileTable = shift; my @tblRows = (); my @fldNames = ('id', 'fio', 'snils', 'no0', 'data', 'vyplata', 'adres_bank0', 'no1', 'no2', 'no3', 'adres_bank1', 'no4', 'no5', 'blank', 'no6'); my %fldNames = (); map { $fldNames{$fldNames[$_]} = $_ } 0..$#fldNames; my $qtyChild = 0; #CSV handle $CSV_H = Text::CSV->new({ sep_char=>";", binary=>1, blank_is_undef=>1, empty_is_undef=>1, allow_whitespace=>0, allow_loose_quotes=>1 ,auto_diag=>1 }); $CSV_H->callbacks(error=>\&csverror2023); if(open my $TBL_H, "<:encoding($codepage)", "$fileTable"){ until($CSV_H->eof){ my $row = $CSV_H->getline($TBL_H); unless($row->[$fldNames{'id'}] !~ /^[[:digit:]]+$/ || $row->[$fldNames{'fio'}] =~ /^[[:digit:]]+$/){ map { printf "%12s: %s\n", $fldNames[$_], $row->[$_] } 0..$#{$row}; push @tblRows, $row; } print '=' x 100, "\n"; } close $TBL_H; } sub csverror2023{ print join('/', @_), "\n"; my $charpos = $_[2]; my $srcstr = $CSV_H->error_input(); printf "ERROR_INPUT: %s\n", $srcstr; unless($CSV_H->eof){ my $badchar = quotemeta(substr($srcstr, $charpos - 1, 1)); printf "BadChar: (%s)\n", $badchar; my $prestr = substr($srcstr, 0, $charpos - 1); printf "PreMatch: (%s)\n", $prestr; $prestr =~ /$badchar[^$badchar]*$/; printf "MATCH_iNDEXES: (%s-%s)\n", $-[0], $+[0]; printf "BadChar0: (%s)\n", substr($prestr, $-[0], 1); substr($srcstr, $-[0], 0, '\\'); printf "ModifiedString: (%s)\n", $srcstr; } $CSV_H->SetDiag(0); }