You can't return a value from the callback, but you can set a variable in it. I changed a bit more in the code, see the comments for explanations.
#!/usr/bin/perl use warnings; use strict; use Text::CSV_XS; # Why not get the full strenth of XS? my $codepage = 'utf8'; binmode(STDOUT, ":$codepage"); binmode(STDIN, ":$codepage"); # STDOIN? #get file names: my $fileTable = shift; my @fldNames = qw( id fio snils no0 data vyplata adres_bank0 no1 no2 n +o3 adres_bank1 no4 no5 blank no6 ); my %fldNum; # Better name @fldNum{@fldNames} = 0 .. $#fldNames; # Shorter, faster. my @tblRows; my $CSV_H = Text::CSV_XS->new({ # Missing "my". 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); my $fixed; 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; $fixed = $srcstr; } $CSV_H->SetDiag(0); } if(open my $TBL_H, "<:encoding($codepage)", $fileTable){ # No need to + double quote a single variable. until($CSV_H->eof){ undef $fixed; my $row = $CSV_H->getline($TBL_H); while ($fixed) { my $line = $fixed; undef $fixed; $CSV_H->parse($line); $row = [$CSV_H->fields]; } unless($row->[$fldNum{id}] !~ /^[[:digit:]]+$/ || $row->[$fldN +um{fio}] =~ /^[[:digit:]]+$/){ printf "%12s: %s\n", $fldNames[$_], $row->[$_] for 0 .. $# +{$row}; push @tblRows, $row; } print '=' x 100, "\n"; } close $TBL_H; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: pass repaired csv string from error handler callback function back to the csv's getline loop for reparsing by choroba
in thread pass repaired csv string from error handler callback function back to the csv's getline loop for reparsing by igoryonya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.