Perl Programming Perl Text: Quoting Without Quote Marks |
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: #!/usr/bin/perl 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: #!/usr/bin/perl $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”
blog comments powered by Disqus |
|
|
|
|
|
|
|