perl function length

https‮/:‬/www.theitroad.com

The length function in Perl is used to determine the length of a string. It takes a single argument, which is the string to be measured, and returns the number of characters in that string.

Here's an example that demonstrates how to use length:

#!/usr/bin/perl

use strict;
use warnings;

# Define a string
my $string = "Hello World";

# Determine the length of the string
my $length = length($string);

# Print the original string and its length
print "String: $string\n";
print "Length: $length\n";

In this example, we start by defining a string called "Hello World". We then use the length function to determine the number of characters in the string and store the result in a new variable called $length. Finally, we print both the original string and its length to the console.

When we run this script, we see that the original string is printed, followed by its length:

String: Hello World
Length: 11