• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

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";
0
blnukem
Asked:
blnukem
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now