1. Computing

Chop()

From , former About.com Guide

Definition:

A function which removes the last character of any string and returns the character removed. You could do this using regular expressions, but chop() is easier and more efficient.

Using Chop() With a Single String

$mystring = "Names";
$a = chop($mystring);
print $a; # displays ‘s’

If you give chop() an empty string, it will return an empty string. If your string is undefined, then chop will return undefined.

Using Chop() With an Array

If you pass chop an array it will remove the last character from every element in the array. This can be useful for removing simple plurals:

@animals = ('dogs', 'cats', 'leopards', 'zebras');
$result = chop(@animals);
foreach my $result (@animals) {
print "$result\n";
}
print "Removed the $result character.
\n";

This produces the output:

dog
cat
leopard
zebra
Removed the s character.

Chop() is Not the Same as Chomp()

Chop will always remove the last character of a string, no matter what it is. This can cause problems if that last character is not what you expect it to be. Chomp can be a safer approach.

©2013 About.com. All rights reserved.