Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Cropping scalar variables with the chop function

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:

    Sol|Selena|sol@foobar.com|456-7890 
    Birznieks|Gunther|gunther@foobar.com|456-7899 
    

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

    Sol|Selena|sol@foobar.com|456-7890\n 
    

  • 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|sol@foobar.com|456-7890\n"; 
    chop ($database_row); 
    

Using the "." Operator
Table of Contents
Finding the length of a scalar variable with the length function


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers