There are numerous built-in functions in Perl, which makes it a very versatile and powerful language. Some of the commonly used built-in functions in Perl along with their purposes are:
1. print() This function is used to print text to the console or a file. It takes one or more arguments and displays them on the screen.
Example:
print "Hello, world!n";
2. chomp() This function is used to remove a newline character from the end of a string. It is often used when reading user input from the keyboard.
Example:
print "Enter your name: ";
my $name = <STDIN>;
chomp $name;
3. length() This function is used to find out the length of a string.
Example:
my $string = "Perl is great";
my $length = length($string);
print "Length of string is $lengthn";
4. split() This function is used to split a string into an array based on a delimiter.
Example:
my $string = "Perl,Programming,is,Great";
my @array = split(",", $string);
print "Array values are: @arrayn";
5. join() This function is used to join an array into a string.
Example:
my @array = ("Perl", "Programming", "is", "Great");
my $string = join(",", @array);
print "Joined string is: $stringn";
6. substr() This function is used to extract a substring from a string.
Example:
my $string = "Perl is Great";
my $substring = substr($string, 0, 4);
print "Substring is: $substringn";
7. push() This function is used to add an element to the end of an array.
Example:
my @array = (1, 2, 3);
push(@array, 4);
print "Array values are: @arrayn";
8. pop() This function is used to remove and return the last element from an array.
Example:
my @array = (1, 2, 3, 4);
my $last = pop(@array);
print "Last element is: $lastn";
These are just a few of the commonly used built-in functions in Perl, but there are many more that can make programming in Perl easier and faster.