switch lvalue substr to 4-arg substr
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 9 Sep 2023 18:26:09 +0000 (11:26 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 9 Sep 2023 18:26:09 +0000 (11:26 -0700)
An advantage is that this makes the calls similar to 4-arg splice.

.perlcriticrc
lib/Perl/Tidy/Tokenizer.pm
lib/Perl/Tidy/VerticalAligner.pm

index 4d3fb85fe9a6b5f5a58a8da5f149604928590ce9..544ee6b595a95bcf2a8ad52cdfc8633f0597b228 100644 (file)
@@ -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
index 36b7544b78ccaface5cc0b33a3b0d2811eb9bbf0..e0467fd6d902a66e5e842ec82d0213d9b3d6050a 100644 (file)
@@ -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
 
index 77385063199c45a22de9c6b6065f0a65aefa43e0..9cb12a989ead38a9f1feace5244530605bdfc53d 100644 (file)
@@ -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 {