Re: 'safe' printing to the terminal

[email protected] ("Philippe Bruhat (BooK)") Wed, 13 May 2026 16:20:03 +0200
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Wed, May 13, 2026 at 10:48:42AM +0000, Michiel Beijen wrote:
> On Wednesday, May 13th, 2026 at 08:30, Aristoteles Pagaltzis via perl5-porters <[email protected]> wrote:
> 
> > `man bash` documents %q as “causes `printf` to
> > output the corresponding argument in a format that can be reused as
> > shell input”, which in in Perl is called \Q (or quotemeta).
> 
> Quotemeta (\Q) is in regexes and is not able to properly filter out terminal escape characters. It does not have anything to do with bash printf %q
> 

Indeed:

    $ perl -E 'print "\e"' | od -a
    0000000 esc
    0000001

    $ perl -E 'print "\Q\e\E"' | od -a
    0000000   \ esc
    0000002

-- 
 Philippe Bruhat (BooK)

 Friendship is just brotherhood with a choice of brothers.
                                                 (Moral from Groo #9 (Image))