From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

String functions

String functions - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

String functions

- [Voiceover] Perl provides a number of useful functions for working with strings. Here's a working copy of string.pl from chapter 13 of the exercise files and you'll notice that we have a string here and if I run this, it outputs that string to the screen using the say function. Now, if I want to, I can get the length of the string and I can say length of string and I can run that and it tells us the length of the string is 51, and again, because this is a built in function I don't actually need the parentheses and that works just exactly the same. The chomp function will remove line endings, if any, and so in this case it returns the number of characters removed and so if I put in a new line at the end here, and I run this you see it's removed one character. And if I go ahead and simply say string, a couple of times you'll see that it's got extra line endings in it. If I come up here and I say chomp $string, then it takes those extra line endings out, it just has the one line ending…

Contents