Home
FREE Newsletter
Perl How To
Perl Books
Perl Basics
Perl Editors
Perl Modules
Perl Database
Net Programming
Sitemap
About Me
Contact Me
Blog
 

Perl qq/STRING/ Function



NEW!!!

Check my new resource:    Perl How To Tutorial eBooks



You can use double quotes if you need to interpolate data before processing.

For instance escape characters can be used to insert newlines, tabs and other special characters into a string.

In the same time the variables that are enclosed in double quotes stings are replaced with their values.

See the following example:

my $str = 'Paris is the most exciting city.';
print "\$str:\t$str\n";
# it prints: 
# $str: Paris is the most exciting city.

my @array = ('one','two','three','four');
print "\@array = @array\n";
# it prints: @array = one two three four

The first example is for strings. The first escape character is used to print the $ special character as a literal character, \t inserts a tab and $str will be interpolated and replaced with its value. Finally, the \n inserts a newline.

The second example shows you how you can interpolate an array variable. The first escape character is used to print @ as a literal character. @array will be interpolated and replaced with the array elements separated by space.

A special case is when you print html tags which requires a lot of double quotes for each tag or when you need to insert double quotes inside a string. The qq/STRING/ operator is used to interpolate variables but to ignore double quotes.

See the following example:

my $str = "It's nice";

print "\"$str\", he said.\n";
# it prints: "It's nice", he said.

print qq/"$str\", he said.\n/;
# it prints: "It's nice", he said.

print q/"$str\", he said.\n/;
# it prints: "$str\", he said.\n

The first print let you display the double quote characters by escaping them.

The second print uses the qq operator to interpolate the $str variable.

The third print uses q (simple quote operator) instead of qq and there are not anyinterpolation here, the $str variable will be literally printed.

The qq operator is used with the / (slash) character as a delimiter, but you can use other delimiters as well. The following lines of code are all equivalent:

my $str = "It's nice";

print qq/"$str\", he said.\n/;
print qq("$str\", he said.\n);
print qq:"$str\", he said.\n:;
print qq%"$str\", he said.\n%;


Check my new How To Tutorial eBook (PDF format):

to see a lot of fully commented examples that help you use the qq/STRING/ function in your scripts.






NEW!!!

Do you want more information about the basic Perl topics?

Check my new "Perl How To" Tutorial eBooks page where I'll answer the most frequent questions regarding some topics :


Perl How To Tutorial eBooks


Table of Contents:

A Perl Script
Install Perl
Running Perl
Perl Data Types
Perl Variables
Perl Operators
Perl Lists
Perl Arrays
    Array Size
    Array Length
Perl Hashes
Perl Statements
    Perl if
    Perl unless
    Perl switch
    Perl while
    Perl do-while
    Perl until
    Perl do-until
    Perl for
    Perl foreach
Built-in Perl Functions
    Functions by Category
        String Functions
        List Functions
        Array Functions
        Hash Functions
        Miscellaneous Functions
    Functions in alphabetical order
        chomp
        chop
        chr
        crypt
        defined
        delete
        each
        grep
        hex
        index
        join
        lc
        lcfirst
        length
        map
        oct
        ord
        pack
        pop
        push
        q
        qq
        qw
        reverse
        rindex
        scalar
        shift
        sort
        splice
        split
        sprintf
        substr
        tr
        uc
        ucfirst
        undef
        unshift

return from Perl qq/STRING/ function to Perl Basics



Would you like to create your own website like this one?
Hit the Alarm Clock!

Site Build It!