my %essential_whitespace_filter_l2;
my %essential_whitespace_filter_r2;
my %is_type_with_space_before_bareword;
+ my %is_special_variable_char;
BEGIN {
@q = qw( Q & );
@is_type_with_space_before_bareword{@q} = (1) x scalar(@q);
+ # These are the only characters which can (currently) form special
+ # variables, like $^W: (issue c066, c068).
+ @q =
+ qw{ ? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ };
+ @{is_special_variable_char}{@q} = (1) x scalar(@q);
+
}
sub is_essential_whitespace {
&& $is_for_foreach{$tokenll}
)
+ # Keep space after like $^ if needed to avoid forming a different
+ # special variable (issue c068). For example:
+ # my $aa = $^ ? "none" : "ok";
+ || ( $typel eq 'i'
+ && length($tokenl) == 2
+ && substr( $tokenl, 1, 1 ) eq '^'
+ && $is_special_variable_char{ substr( $tokenr, 0, 1 ) } )
+
# We must be sure that a space between a ? and a quoted string
# remains if the space before the ? remains. [Loca.pm, lockarea]
# ie,
=over 4
-=item B<Handle parsing problem issue c066>
+=item B<Fix parsing issue c068>
+
+This issue is illustrated with the following line:
+
+ my $aa = $^ ? "defined" : "not defined";
+
+If we tell perltidy to remove the space before the '?', then the output
+will no longer be a valid script:
+
+ # perltidy -nwls='?':
+ my $aa = $^? "defined" : "not defined";
+
+The problem is that Perl considers '$^?' to be a special variable. So Rerunning
+perltidy on this gives an error, and perl also gives an error. This update
+fixes the problem by preventing a space after anything like '$^' from being
+removed a new special variable would be created.
+
+This fixes issue c068.
+
+7 Sep 2021.
+
+
+=item B<Fix parsing problem issue c066>
This issue is illustrated with the following line (rt80058):