Barry Brevik wrote: > I can't believe this has me stymied, but here goes... > > I'm processing a string of chars in a loop, and the string can contain > multiple lines; that is, the string has embedded "\n" chars in it. For > display purposes, I need to count the number of "\n" chars in each > string. Is there a simple way to do this?
tr returns the number of characters replaced or deleted, so you could just do: use strict; use warnings; my $str = "abc\ndef\nghi\njkl\nmno\npqr\nstu\nwx\nyz\n"; my $cnt = $str =~ tr/\n/\n/; print "cnt=$cnt\n"; __END__ _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs