This appears to do what you require:
my $string = "test\nI want length of this line\n test"; my $position = 12; # Note this postion can be any position in any line +. currently considering it inside 2nd line my $length_of_line; if ( $string =~ /\n.*(?=\n)/ && $-[ 0 ] < $position && $+[ 0 ] > $posi +tion ) { $length_of_line = $+[ 0 ] - $-[ 0 ]; }
In reply to Re: Finding length of line if have any position of any char inside line
by jwkrahn
in thread Finding length of line if have any position of any char inside line
by phoenix007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |