introduction to web programming Cropping scalar variables with the chop function Sometimes, you do not want the entire value that has been assigned to a scalar variable. For example, it is often the case that the lines you retrieve from a data file will incorporate a new line character at the end of the line. Data files often take advantage of the new line character as a "database row delimiter". That is, every line in a database file is a new database item. For example, here is a snippet from an address book data file:


When the script reads each line, it also reads in the new line information. Thus, the first line is actually represented as:


The final "\n" is a new line. Since we do not actually want the "\n" character included with the last database field, we use the chop function. The chop function chops off the very last character of a scalar variable using the syntax:

    chop ($variable_name);

Thus, we would take off the final new line character as follows:

    $database_row = "Sol|Selena||456-7890\n";
    chop ($database_row);

Previous | Next | Table of Contents