Perl programming: printing a string
Tutoring web programming, you might encounter a question about Perl. The tutor mentions an observation.
Because inline styles use quotes, and then of course printing a string often uses quotes around it, a situation can easily develop in which nested quotes occur. In my experience, the nested quotes need to be different somehow, as
print "this text gives "that text" as its message";
seems not to work.
However, here are a couple of options:
- Using different types of quotes for outer vs inner strings:
print "enclosing 'inner string' string";
-
print "enclosing \"inner string\" string";
With the second option, the inner quotes are escaped. Then, Perl reads them simply as symbols rather than having specific meaning, so it just passes them along.
Source:
McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.