Perl chop Function

Advertisements


Description

This function removes the last character from EXPR, each element of LIST, or $_ if no value is specified.

Syntax

Following is the simple syntax for this function:

chop VARIABLE

chop( LIST )

chop

Return Value

This function returns the character removed from EXPR and in list context, the character is removed from the last element of LIST.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

$string1 = "This is test";
$retval  = chop( $string1 );

print " Choped String is : $string1\n";
print " Character removed : $retval\n";

When above code is executed, it produced following result:

Choped String is : This is tes
Number of characters removed : t


Advertisements
Advertisements