Scalar Data

The chop and chomp functions

The chop function chops off the last character of a string and returns the character chopped.

Example:

$a = "Molecular Biology";
$b = chop($a);

now $a is:   Molecular Biolog
and $b is:   y

chomp is slightly a safer version of chop in that it removes only the last newline character, and not any last character.


Note:
Use chop and chomp only with variables, not with literal values.

Example:

$b = chop ("Molecular Biology");

is illegal!


Table of Contents.
Previous | Next.