Mathi Maheswaran
Mathi Maheswaran

Reputation: 59

Finding tabs and white spaces inside the file in Perl

We are doing the our code review manually. It's eating our more time to review the each and every file. We are checking below generic items for all the files. It would be good if any automated script in Perl / Php for code review.

  1. List out the total number of tabs used inside the files.
  2. List out the total number of white spaces inside the files.

Kindly help to create automated tool for code review.

Thanks in advance.

Upvotes: 0

Views: 56

Answers (1)

Miller
Miller

Reputation: 35198

I'm amused by the idea of you or someone manually counting the tabs.

Count tabs:

perl -ne '$c += () = /\t/g; END{print qq{$c}}' file.pl

or

perl -ne '$c += tr/\t//; END {print qq{$c}}' file.pl

And similarly for white spaces:

perl -ne '$c += tr/ //; END {print qq{$c}}' file.pl

Upvotes: 1

Related Questions