Strings
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

Strings

There are several ways of quoting strings in perl, corresponding to the three quote characters on the keyboard.
' (apostrophe)
The simplest quote, text placed between a pair of apostrophes is interpreted literally - no variable expansion takes place.
To include an apostrophe in the string, you must escape it with a backslash '\'
 
	$instrument = 'saxophone'; 
	$littleInstrument = 'soprano $instrument'; 
	# the string value of $littleInstrument includes the 
	#   text "$instrument" - probably an error in this case. 
" (double quotes)
The double quote "interpolates" variables between the pair of quotes.
 
	$instrument = "saxophone"; 
	$littleInstrument = "soprano $instrument"; 
	# the string value of $littleInstrument is "soprano saxophone" 
To include an apostrophe in the string, you must escape it with a backslash '\'.
` (backtick)
This quote performs as it does in the UNIX shells - the text inside the backticks is executed as a separate process, and the standard output of the command is returned as the value of the string.
Backticks perform variable interpolation, and to include a backtick in the string, you must escape it with a backslash '\'.
 
	$memberList = "/usr/people/conductor/roster"; 
	$memberCount = `wc -l $memberList`; 
	# $memberCount is the number of members in the conductor's roster, 
	# assuming that each member is listed on a separate line. 

Example

 
        # the sendmail binary. 
        $sendmail = "/usr/lib/sendmail"; 
         
        # base of your httpd installation. 
        $basedir = '/www'; 
        # log file 
        $logfile = "$basedir/etc/logs/$progname.log"; 
         
        # today 
        $date = `date`; 

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/strings.html at 08/02/99