Home arrow Perl Programming arrow Perl Text: Quoting Without Quote Marks

Perl Text: Quoting Without Quote Marks

In our last article we introduced you to using text in Perl. By the time we were done, there was text everywhere. But that's okay. In this tutorial we will learn to clean that text up and put it in its place. So roll up those sleeves and prepare to get organized. No more sloppy text for you!

  1. Perl Text: Quoting Without Quote Marks
  2. Working with the Here Document...Over There
  3. Formatting with the Here Document
  4. You Can Look But Don't Touch
By: James Payne
Rating: starstarstarstarstar / 2
March 03, 2008

print this article



We left off discussing how to use special characters and escape characters like the newline and tab to determine how our text is displayed. We also talked about the effects of single and double quotes. Here, we will begin by discussing two functions you can use in place of the single and double quote.

Q...QQ...Q...I Got You!

Have you ever played a game of cops and robbers with a four year old before? You can't win it. You point your finger at the kid and make the gun sound (q...qq...q...q) and the kid is like NEO from the Matrix. Clearly you shot him; you emptied your whole finger canon at him point blank, but the little punk swears you didn't shoot him. Then he shoots back at you, with his finger pointing at the ceiling and swears he shot you. I mean what the hell? The next thing you know, the couch is tipped over, the kid is crying, and his parents are looking at you like you did something wrong, when clearly, you won the gun fight. And all that whiny kid has to say is: Nuh....UH!

In addition to using the single and double quotes, you can use the q and qq functions. The q function takes the place of the single quote, while qq takes the place of the double. Here it is in code:


print "\n\n";

print q/How's it going?/;

print "\n\n";

print q|What's that over there?|;

print "nn";

print qq[And then he said, "How are you?"];

print "\n\n";

This results in the print out:

  How's it going?


  What's that over there?

  And then he said, “How are you?”

You will note that we start the function with either a q or qq, and follow it with a delimiter. We then end the quote with the right-side delimiter. The left delimiter can be: <, , /, |, {, or [ and the right delimiter can be: >, /, , |, } or ].

You can also use these functions when defining a variable:


$first=q<That's how you make a single quote>;

$second=qq{I said, "This is how you make a double quote"};

print $first;

print "\n\n";

print $second;

Which results in:

  That's how you make a single quote

  I said, “This is how you make a double quote”

>>> More Perl Programming Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates


Dev Shed Tutorial Topics: