String::PerlQuote - Quote a string as Perl does
This document describes version 0.02 of String::PerlQuote (from Perl distribution String-PerlQuote), released on 2016-10-07.
Quote or encode $str to the Perl double quote (") literal representation of the string. Example:
$str
"
say double_quote("a"); # => "a" (with the quotes) say double_quote("a\n"); # => "a\n" say double_quote('"'); # => "\"" say double_quote('$foo'); # => "\$foo"
This code is taken from quote() in Data::Dump. Maybe I didn't look more closely, but I couldn't a module that provides a function to do something like this. String::Escape, for example, provides qqbackslash but it does not escape $.
quote()
qqbackslash
$
Like double_quote but will produce a Perl single quote literal representation instead of the double quote ones. In single quotes, only literal backslash \ and single quote character ' are escaped, the rest are displayed as-is, so the result might span multiple lines or contain other non-printable characters.
double_quote
\
'
say single_quote("Mom's"); # => 'Mom\'s' (with the quotes) say single_quote("a\\"); # => 'a\\" say single_quote('"'); # => '"' say single_quote("\$foo"); # => '$foo'
Please visit the project's homepage at https://metacpan.org/release/String-PerlQuote.
Source repository is at https://github.com/perlancar/perl-String-PerlQuote.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=String-PerlQuote
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install String::PerlQuote, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::PerlQuote
CPAN shell
perl -MCPAN -e shell install String::PerlQuote
For more information on module installation, please visit the detailed CPAN module installation guide.