您的位置:寻梦网首页编程乐园CGI编程Zhanshou's CGI Tutorial

Strings


Three quote characters are used in quoting strings in perl. They are used in different ways.

  • ' (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 '\'

     
        $string1 = 'chocolate'; 
        $string2 = 'I love $string1';   # The value of $string2 is "I love $string1" 
    
  • " (double quotes)

    The double quote "interpolates" variables between the pair of quotes.

     
        $string1 = "chococlate"; 
        $string2 = "I love $string1";   #Now the value of $string2 is "I love chocolate" 
    
    To include an apostrophe in the string, you must escape it with a backslash '\'.

  • ` (backtick)

    Backtick usually quotes UNIX shell commands. The execution result 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 '\'.

     
        $document = "/home/document.txt"; 
        $WordCount = `wc -w $document`;
        # $WordCount get the number of words in the " /home/document.txt" file.  
        # here  is a UNIX command which counts the number of lines, words or characters of a file.
    

Here are some examples:

        # 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`; # where date is a UNIX shell command that returns today's date 

Previous Page Table of Content Next Page