Perl Functions
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

Perl Functions

Perl has many builtin functions, and instead of trying to describe them all, I'll cover their syntax. Refer to other sources for full documentation.

Perl functions are identified by their unique names (print,chop,close, etc). For clarity's sake, the function's arguments are supplied as a comma separated list in parenthesis. The commas are necessary, the parentheses are often not.

 
	print("length: " ,length("hello world")); 
	# prints the same thing as 
	print "length: ",1, length "a"; 
The latter example hints at perl's beastiness. For our purposes, we'll always use parenthesis.

Example

For our script, we wan't to save the date the form was filled out more clearly than the date in the mail headers.
 
	... 
	$date = `date`; 
	chop($date); 
	# begin CGI output  
	print("Content-type: text/html\n\n"); 
The first line executes the UNIX command date and puts the output in the the variable $date. Sine the date has a newline on it, we want to chop that off. Also, we'll initialize the output of the CGI script - necessary for successful presentation of the results
left up right comment



NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

johnsonb@ncsa.uiuc.edu

Last modified: June 19, 1997



Retrieved by Memoweb from http://www.ncsa.uiuc.edu/General/Training/PerlIntro/funtions.html at 08/02/99