]> git.donarmstrong.com Git - perltidy.git/commitdiff
add note for git#24, note about adding spaces
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 28 Apr 2020 02:47:30 +0000 (19:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 28 Apr 2020 02:47:30 +0000 (19:47 -0700)
bin/perltidy

index 5e4388a6479b8c6f04c8c3def4ac43b4891d68e0..0c7983fd0a32d90be47828f0e9b39c2704d72a8b 100755 (executable)
@@ -1078,6 +1078,26 @@ and look at the .DEBUG file to see the tokenization.
 B<WARNING> Be sure to put these tokens in quotes to avoid having them
 misinterpreted by your command shell.
 
+=item Note: Perltidy does always follow whitespace controls 
+
+The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done.   Examples are whitespace around bareword symbols and possible filehandles.  For example, consider the problem of formatting the following subroutine:
+
+   sub print_div {
+      my ($x,$y)=@_;
+      print $x/$y;
+   }
+
+Suppose the user requests that / signs have a space to the left but not to the right. Perltidy will refuse to do this, but if this were done the result would be
+   
+   sub print_div {
+       my ($x,$y)=@_;
+       print $x /$y;
+   }
+
+If formatted in this way, the program will not run (at least with recent versions of perl) because the / is assumed to start a quote. In a complex program, Perl might find a terminating / to the multiline quote and run, but incorrectly.
+
+Similar issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators.  So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged.  Likewise, whitespace around barewords is left unchanged. But the bigger picture is that it is risky write programs which do math operations involving a term which could be taken to be a filehandle.
+
 =item Space between specific keywords and opening paren
 
 When an opening paren follows a Perl keyword, no space is introduced after the