# Perl quoting convention that avoids excessive backslashes

**URL:** <https://www.ruby-forum.com/t/perl-quoting-convention-that-avoids-excessive-backslashes/153911>\
**Category:** Ruby\
**Created:** [November 22, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/perl-quoting-convention-that-avoids-excessive-backslashes/153911 "2008-11-22T22:20:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kelly\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@Kelly\_J](https://www.ruby-forum.com/u/Kelly_J)\
**Post date:** [November 22, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/perl-quoting-convention-that-avoids-excessive-backslashes/153911/1 "2008-11-22T22:20:28Z")

</div>

Perl lets you quote strings like this:

$foo = qq%This string has both “quotes” and ‘apostrophes’%;

to avoid excessive backslashing.

Does ruby have anything similar?

---

<div class="post-metadata">

**Author:** ![Kelly\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@Kelly\_J](https://www.ruby-forum.com/u/Kelly_J)\
**Post date:** [November 22, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/perl-quoting-convention-that-avoids-excessive-backslashes/153911/2 "2008-11-22T22:27:30Z")

</div>

Alle Saturday 22 November 2008, Kelly J. ha scritto:

> Perl lets you quote strings like this:
> 
> $foo = qq%This string has both “quotes” and ‘apostrophes’%;
> 
> to avoid excessive backslashing.
> 
> Does ruby have anything similar?

Yes:

%Q["abc 'def]

and

%["abc 'def]

create a string which can contain string interpolation:

%Q[{1+1}]  
=\> “2”

%q["abc 'def]

creates a string without string interpolation:

%q[#{1+1}]  
=\> “#{1+1}”

You can replace the [] with (), {} or \<\> or with any non alphanumeric  
character (that is any character excluding letters and digits):

%q{“abc”}  
%q!abc!

I hope this helps

Stefano
