The uninterpreted quote operator q{} takes you most of the way. There are only a few subtle differences.
delimiters
There are four delimiters that are used with Python string literals:
r"..." and r'...'r"""...""" and r'''...'''
The q... operator in Perl has a wider variety of delimiters
- Conjugate delimiters
q(...) , q[...] , q<...> , q{...} - Regular delimiters can be any other non-letter, 7-bit ASCII char:
q"..." , q/.../ , q#...# , etc.
backslash
The backslash character \ always interpreted as the literal backslash character in Python literal string strings. It will also skip the character, which is otherwise interpreted as a trailing line separator.
r'Can\'t believe it\ not butter' => Can\'t believe it\ not butter
The backslash \ in Perl q{...} also a literal backslash with two exceptions:
The backslash precedes the delimiter character
q<18 \> 17 \< 19> => 18 > 17 < 19 q
A backslash precedes another backslash character. In this case, the sequence of two backslash characters is interpreted as one backslash.
q[single \ backslash] => single \ backslash q[also a single \\ backslash] => single \ backslash q[double \\\ backslash] => double \\ backslash q[double \\\\ backslash] => double \\ backslash
There is one way to create a truly βrawβ string in Perl: the one-shot doc here.
my $string = <<'EOS'; '"\\foo EOS
This creates the string '"\\fooNEWLINE .
(So, is it possible to create one string string literal in Python that contains both ''' and """ ?)
source share