Count Lines In A String

Hi All

How can I count the number on lines in this string:

$Text = "this is my\n new text\n message\n goodbye";

RESULT:
$LineCount = "4";
blnukemAsked:
Who is Participating?
 
Adam314Commented:

my $Text = "this is my\n new text\n message\n goodbye";
chomp($Text);
my $count = ($Text =~ tr/\n/\n/ + 1);
print "count=$count\n";

Open in new window

0
 
blnukemAuthor Commented:
Thanks! Adam314
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.