Perl String Escaping Characters

All the special characters or symbols like @, #, $, & /, \, etc does not print in a normal way. They need a preceding escaping character backward slash (\) to get printed.


Perl Displaying E-mail Address

All the e-mail addresses contain (@) sign. As stated earlier, symbols will not be printed normally inside a string. They need extra attention. Use backward slash (\) before @ sign to print e-mail addresses.

Output:


Perl $ sign Embedding in Double quote String

If we want to print ($) sign inside a string, use backward slash (\) preceding $ sign.

Output:

We have defined $msg1 as Ana

Perl Escaping Escape Character

If we want to print (\) sign inside a string, use backward slash (\) preceding \ sign.

Output:

Everyone has to follow this rule whether its a boy\girl

Perl Escaping Double quotes

If you want to print double quotes inside a string use backslash (\) at both the quotes.

Output:

Our site "javaTpoint" provides all type of "tutorials?

Perl Double-q Operator, qq

The "qq" operator replaces the double quote surrounding a string by its parentheses. It means ("") are not essential on this string anymore. It will simply print the string with qq.

But if you want a bracket inside a string then you need to use curly braces {} surrounding the string.

And if you need curly braces inside the string then use square bracket [] surrounding the string.

Output:

Our site "javaTpoint" provides all type of "tutorials"
Our site (javaTpoint) provides all type of "tutorials"
Our site (javaTpoint} provides all type of "tutorial"

Perl Single-q Operator, q

The single 'q' operator works as the single quote (') in the string. Like single quote, it also does not interpolate the variables.

Output:

Our site "javaTpoint" provides all type of "$x"\n
Our site "javaTpoint" provides all type of "$x" \n
Our site )javaTpoint( provides all type of "$x" \n
Our site )javaTpoint} provides all type of "$x" \n