From 309548ea5fc42e950c05f11d88718e19d32b3a52 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 9 Sep 2023 11:26:09 -0700 Subject: [PATCH] switch lvalue substr to 4-arg substr An advantage is that this makes the calls similar to 4-arg splice. --- .perlcriticrc | 4 ---- lib/Perl/Tidy/Tokenizer.pm | 4 ++-- lib/Perl/Tidy/VerticalAligner.pm | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 4d3fb85f..544ee6b5 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -91,10 +91,6 @@ max_nests=9 [-ClassHierarchies::ProhibitExplicitISA] -# I find that using lvalue substr much clearer than adding another arg to -# substr. So skip this one. -[-BuiltinFunctions::ProhibitLvalueSubstr] - # There is one complex regex in Tokenizer.pm for scanning numbers. It is # well commented and easy to read, and any changes would make it harder # to read. But rather than deactivate this policy, I have adjusted the diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 36b7544b..e0467fd6 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -4559,7 +4559,7 @@ EOM # unless the word is __END__ or __DATA__ and is the only word on # the line. && ( !defined( $is_END_DATA{$tok_kw} ) - || $input_line !~ /^\s*__(END|DATA)__\s*$/ ) + || $input_line !~ /^\s*__(?:END|DATA)__\s*$/ ) ) { $self->do_QUOTED_BAREWORD(); @@ -10077,7 +10077,7 @@ sub write_on_underline { if ( $excess > 0 ) { $pos_chr = substr( $pos_chr, 0, length($pos_chr) - $excess ); } - substr( $underline, $pos, length($pos_chr) ) = $pos_chr; + substr( $underline, $pos, length($pos_chr), $pos_chr ); return ($underline); } ## end sub write_on_underline diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 77385063..9cb12a98 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -5582,7 +5582,7 @@ sub valign_output_step_D { int( $leading_space_count / $rOpts_entab_leading_whitespace ); my $leading_string = "\t" x $tab_count . SPACE x $space_count; if ( $line =~ /^\s{$leading_space_count,$leading_space_count}/ ) { - substr( $line, 0, $leading_space_count ) = $leading_string; + substr( $line, 0, $leading_space_count, $leading_string ); } else { @@ -5617,7 +5617,7 @@ sub valign_output_step_D { $leading_string .= ( SPACE x $space_count ); } if ( $line =~ /^\s{$leading_space_count,$leading_space_count}/ ) { - substr( $line, 0, $leading_space_count ) = $leading_string; + substr( $line, 0, $leading_space_count, $leading_string ); } else { -- 2.39.5