Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is it possible to force all one-line string scalars to be single-quoted? #40

Open
bpj opened this issue Dec 16, 2020 · 1 comment
Labels

Comments

@bpj
Copy link

bpj commented Dec 16, 2020

The title nearly says it all. The two additional points are that I would like also keys to be single-quoted and would prefer that keys/values containing only ASCII alphanumerics and SPACE would be exempt.

@perlpunk
Copy link
Owner

perlpunk commented Apr 7, 2021

Sorry for the late answer, I have been extremely busy.

There are no options to customize quoting like that yet.
What you can do is to preprocess the structure yourself and create objects that preserve quoting style:

use YAML::PP;
use YAML::PP::Common qw/ PRESERVE_SCALAR_STYLE YAML_SINGLE_QUOTED_SCALAR_STYLE /;        
my $yp = YAML::PP->new( preserve => PRESERVE_SCALAR_STYLE );
my $h = $yp->preserved_mapping({}); # We need this to be able to store objects as keys
my $scalar = $yp->preserved_scalar("my special string", style => YAML_SINGLE_QUOTED_SCALAR_STYLE );
$h->{ $scalar } = $scalar;
my $dump = $yp->dump_string($h);
say $dump;
__END__
---
'my special string': 'my special string'

Let me know if this works for you and if you find it useful or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants