Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.93k stars 549 forks source link

Data::Dumper feature request: Flag to use hex escapes for quoted strings instead of octal #19906

Open zmughal opened 2 years ago

zmughal commented 2 years ago

Module: Data::Dumper

Description

Currently the Useqq flag / qquote function of Data::Dumper only uses \x-style hex escapes on non-ASCII codepoints and octal for others. Of note, this means that control characters (/[\x00-\x1F]/) are represented in octal.

It might be useful to have a flag to prefer hex escapes over octal escapes for these non-printables.

Steps to Reproduce

$ print Data::Dumper->new(["\x1f\x{FFF}"])->Useqq(1)->Terse(1)->Dump
"\37\x{fff}"

Expected behavior

$ print Data::Dumper->new(["\x1f\x{FFF}"])->Usehex(1)->Useqq(1)->Terse(1)->Dump
"\x{1f}\x{fff}"
jkeenan commented 2 years ago

Module: Data::Dumper

Description

Currently the Useqq flag / qquote function of Data::Dumper only uses \x-style hex escapes on non-ASCII codepoints and octal for others. Of note, this means that control characters (/[\x00-\x1F]/) are represented in octal.

It might be useful to have a flag to prefer hex escapes over octal escapes for these non-printables.

Steps to Reproduce

$ print Data::Dumper->new(["\x1f\x{FFF}"])->Useqq(1)->Terse(1)->Dump
"\37\x{fff}"

Am I correct in thinking that what you really intended to say here at the command-prompt was this?

$ perl -MData::Dumper -e 'print Data::Dumper->new(["\x1f\x{FFF}"])->Useqq(1)->Terse(1)->Dump'
"\37\x{fff}"
zmughal commented 2 years ago

Am I correct in thinking that what you really intended to say here at the command-prompt was this?

I should have clarified that I was copying from a REPL prompt, but yes, that's how it would run from the shell.