![]() ![]() Lets take the same example that we have seen above in double q operator. ![]() ![]() The special characters present inside it does not interpolate. Single q operator works like single quotes. See I have not used the escape sequences for the double quotes and brackets. Output: My name is "Chaitanya" and I like brackets () Print qq(My name is "$name" and I like brackets ()\n) The advantage of doing this is that we need not to worry about using escape sequences for double quotes(“) and brackets. We can replace the double quotes that we use to enclose a string with the double q operator. As we have discussed in the Scalars guide that string is considered as scalar variable in Perl programming language. Output: I like to watch "The Walking Dead" Double q operator – qq Download ActivePerl String-Compare 0.4 Compare two strings and return how much they are alike INSTALL> ppm install String-Compare Links CPAN Author Daniel Ruoso Lastest release version 0. My $say = "I like to watch \"The Walking Dead\"" Create your free Platform account to download ActivePerl or customize Perl with the packages you require and get automatic updates. We will use the same approach by escaping the quotes using \. Lets say we want to display a String in Perl and the string itself has a double quotes in it. We know that a text inside double quotes is treated as string in Perl. My $say = 'I do like to use backslash \\' Īs you can see we have \ displayed in the output. Lets take an example to understand this: use strict For this, you would want to escape the backslash. In the above examples, we have used the backslash to escape the special characters $ and There may be a case where you would want to display the backslash in the output. $msg: I am Negan How to escape the escape character backslash (\) # escaping the first dollar sign but not escaping the second In case you want to escape the $ sign and avoid the interpolation, use the same trick we have done above – prefix it with backslash. Output: Escaping the $ sign in double quote stringsĪs we already know that dollar sign interpolates to the value of the variable. # no backslash needed as interpolation does not In case of single quotes no need to use the the escape sequence because interpolation doesn’t happen in single quote strings. In the following example if we do not place the backslash before the then instead of displaying the email, it would throw an error because it will consider as an array. As we already know that when we place the special characters inside double quote strings then perl tries to interpolate it. The character has a special meaning in perl. In this guide, we will discuss the escape characters that will help us achieve desired output in certain cases. In the previous tutorial we have learned how to work with Strings in Perl. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |