in reply to how to get length of each line of file with spaces
You could use something like my $l = length($string =~ s/\t/ /gr), though that's rather inefficient. Another solution:
my $tablength = 4; my $string = "\tSample\ttext."; my $expanded_length = render_length($string, $tablength); sub render_length { my ($string, $tabl) = @_; my $length = length($string); my $tabcount = $string =~ tr/\t//; $length += ($tabl - 1) * $tabcount; return $length; }
This isn't terribly elegant (wrote it on the train on the way to work), but it should work fine, except that the entire notion of tab length is a choice that you make, and convention is ambiguous.
Dave
|
|---|