Using tr/// as davido suggests can very efficiently count characters and also exclude characters from a count with the /c modifier (see tr/// in the Quote-Like Operators section of perlop):
c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qq(pp); ;; my $entab = 4; ;; my @lines = ( qq{This line has no tab.\n}, qq{\tThis line has tab at the beginning.\n} ); ;; for my $line (@lines) { my $rend = ($line =~ tr/\t//c) + ($entab * $line =~ tr/\t//); printf qq{%s renders as %d chars long \n}, pp($line), $rend; } " "This line has no tab.\n" renders as 22 chars long "\tThis line has tab at the beginning.\n" renders as 40 chars long
Give a man a fish: <%-{-{-{-<
In reply to Re: how to get length of each line of file with spaces
by AnomalousMonk
in thread how to get length of each line of file with spaces
by phoenix007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |