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

Absorber printf conversion #17166

Open
p5pRT opened this issue Oct 2, 2019 · 4 comments
Open

Absorber printf conversion #17166

p5pRT opened this issue Oct 2, 2019 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 2, 2019

Migrated from rt.perl.org#134467 (status was 'open')

Searchable as RT134467$

@p5pRT
Copy link
Author

p5pRT commented Oct 2, 2019

From @jidanni

Created by jidanni@gmail.com

For cases like

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D Z=%d\n", @​xyz[ 0, 2 ];'
X=1 Z=3

how about offering a different way​: introducing the "absorber conversion"!

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D%q Z=%d\n", @​xyz;'
X=1 Z=3

That's right, "%q" has simply eaten its argument and done nothing!

Why would anybody want to do that? Well at least give users a choice.

(Just like the "unpack" function has an "x" template. See perlpacktut.)

Perl Info

Flags:
    category=core
    severity=wishlist

Site configuration information for perl 5.28.1:

Configured by Debian at Sun Mar 31 11:51:22 UTC 2019.

Summary of my perl5 (revision 5 version 28 subversion 1) configuration: ...

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2019

From @jkeenan

On Wed, 02 Oct 2019 19​:57​:25 GMT, jidanni wrote​:

This is a bug report for perl from jidanni@​gmail.com,
generated with the help of perlbug 1.41 running under perl 5.28.1.

-----------------------------------------------------------------
[Please describe your issue here]

For cases like

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D Z=%d\n", @​xyz[ 0, 2 ];'
X=1 Z=3

how about offering a different way​: introducing the "absorber conversion"!

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D%q Z=%d\n", @​xyz;'
X=1 Z=3

That's right, "%q" has simply eaten its argument and done nothing!

Why would anybody want to do that? Well at least give users a choice.

(Just like the "unpack" function has an "x" template. See perlpacktut.)

Do you have any prior art for this feature request?

Internet search for "absorber conversion" mainly turns up links for automotive shock absorbers?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 2019

From @tonycoz

On Wed, 02 Oct 2019 12​:57​:25 -0700, jidanni wrote​:

For cases like

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D Z=%d\n", @​xyz[ 0, 2 ];'
X=1 Z=3

how about offering a different way​: introducing the "absorber conversion"!

$ perl -we '@​xyz = ( 1 .. 3 ); printf "X=%D%q Z=%d\n", @​xyz;'
X=1 Z=3

That's right, "%q" has simply eaten its argument and done nothing!

Why would anybody want to do that? Well at least give users a choice.

(Just like the "unpack" function has an "x" template. See perlpacktut.)

You can already use %.0s to do this​:

$ perl -le 'printf "%s%.0s%s\n", "a", "b", "c"'
ac

though this will try to convert that second parameter to a string, which may have side-effects (like a warning if it's undef.)

$ perl -Wle 'printf "%s%.0s%s\n", "a", undef, "c"'
Use of uninitialized value in printf at -e line 1.
ac

You can already reference printf parameters by index​:

$ perl -le 'printf q(%1$s%3$s), "a", "b", "c\n"'
ac

which avoids the side-effects​:

perl -le 'printf q(%1$s%3$s), "a", undef, "c\n"'
ac

I don't know that there's much value to this change.

Tony

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

No branches or pull requests

2 participants