phoenix007 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am trying to find out length of each line of file. I am using length function. Problem is length function is counting tab as a single char and not as 4 chars
input file :
This line has no tab. This line has tab at the beginning.
Script I am using :
open(my $fh, '<', $inputfile); my %line_chars; my $line_number = 1; while (my $row = <$fh>) { if ($line_number > 1) { $line_chars{$line_number} = $line_chars{$line_number - +1} + length($row); } else { $line_chars{$line_number} = length($row); } $line_number++; }
Here I need output with all spaces before and after line. specially when line starts with tab
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to get length of each line of file with spaces
by Fletch (Bishop) on May 17, 2019 at 12:47 UTC | |
by Eily (Monsignor) on May 17, 2019 at 19:38 UTC | |
by afoken (Chancellor) on May 18, 2019 at 09:53 UTC | |
|
Re: how to get length of each line of file with spaces
by AnomalousMonk (Archbishop) on May 17, 2019 at 15:35 UTC | |
|
Re: how to get length of each line of file with spaces
by davido (Cardinal) on May 17, 2019 at 14:23 UTC | |
|
Re: how to get length of each line of file with spaces
by Laurent_R (Canon) on May 17, 2019 at 17:59 UTC | |
|
Re: how to get length of each line of file with spaces
by Your Mother (Archbishop) on May 17, 2019 at 17:54 UTC |