With many editors, it can be common to write new code or modify existing one, so that some lines will contain trailing whitespace, such as spaces (ASCII 32 or 0x20) or tabs characters. These trailing spaces normally do not cause much harm, but they are not needed, harm the code’s consistency, may undermine analysis by patching/diffing and version control tools. Furthermore, they usually can be eliminated easily without harm.
Here is an example of having trailing whitespace demonstrated using the --show-ends
flag of the GNU cat command:
> cat --show-ends toss-coins.pl #!/usr/bin/perl$ $ use strict;$ use warnings;$ $ my @sides = (0,0);$ $ my ($seed, $num_coins) = @ARGV;$ $ srand($seed); $ $ for my $idx (1 .. $num_coins)$ {$ $sides[int(rand(2))]++;$ $ print "Coin No. $idx\n";$ }$ $ print "You flipped $sides[0] heads and $sides[1] tails.\n";$ >
While you should not feel bad about having trailing space, it is a good idea to sometimes search for them using a command such as ack '[ \t]+$'
(in version 1.x it should be ack -a '[ \t]+$'
, see ack), and get rid of them.
Some editors also allow you to highlight trailing whitespace when present. See for example:
Finally, one can check and report trailing whitespace using the following CPAN modules: