From fed0f57bd3a3579955493b4de02cb349450ccfe8 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 23 Oct 2023 07:55:54 -0700 Subject: [PATCH] check for and warn on non-ascii characters in perltidy modules These are undesirable. For example, even 1 non-ascii char forces a very slow check for utf-8 every time perltidy reformats itself, which is often. --- pm2pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pm2pl b/pm2pl index 99da1ccb..e5819262 100755 --- a/pm2pl +++ b/pm2pl @@ -82,10 +82,13 @@ $fh_out->print($hash_bang); # then copy all modules my $changed_count; foreach my $module (@modules) { + my @non_ascii; + my $lno=0; my $fh_module; open( $fh_module, '<', $module ) or die "can't open my module file '$module' : $!\n"; while (<$fh_module>) { + $lno++; last if /^\s*__END__\s*$/; my $line = $_; if ( $Opts{'D'} @@ -101,8 +104,25 @@ EOM } $fh_out->print($line) unless $line =~ /^use Perl::Tidy/; + + if ( $line =~ /[^[:ascii:]]/g ) { + my $pos = pos($line); + push @non_ascii, [ $lno, $pos ]; + } } $fh_module->close(); + + if (@non_ascii) { + my $num = @non_ascii; + my ( $lno_first, $pos_first ) = @{ $non_ascii[0] }; + print STDERR <