http://qs1969.pair.com?node_id=11144669


in reply to Problem with escape sequence \x for hex with spaces "\x{ 263A }"

G'day Rolf,

That feature was introduced in v5.34: "perl5340delta: Blanks freely allowed within but adjacent to curly braces".

My tests:

$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -MCarp::Always -E +' $ perlbrew switch perl-5.32.0 $ perle 'say $]; say join ",",map {ord} split //, $_ for "\x{ 41 }", " +\x{41}", "\x{263A}", "\x{ 263A }"; say for "\x{41}", "\x{ 41 }"' Non-hex character ' ' terminates \x early. Resolved as "\x{00}" at -e + line 1. Non-hex character ' ' terminates \x early. Resolved as "\x{00}" at -e + line 1. Non-hex character ' ' terminates \x early. Resolved as "\x{00}" at -e + line 1. 5.032000 0 65 9786 0 A $ perlbrew switch perl-5.34.0 $ perle 'say $]; say join ",",map {ord} split //, $_ for "\x{ 41 }", " +\x{41}", "\x{263A}", "\x{ 263A }"; say for "\x{41}", "\x{ 41 }"' 5.034000 65 65 9786 9786 A A

It's not mentioned in perlop, so a doco omission but not a bug in Perl itself. Perhaps raise a doco bug report.

— Ken

  • Comment on Re: Problem with escape sequence \x for hex with spaces "\x{ 263A }"
  • Download Code

Replies are listed 'Best First'.
Re^2: Problem with escape sequence \x for hex with spaces "\x{ 263A }"
by LanX (Saint) on Jun 10, 2022 at 20:55 UTC
    Hi Ken,

    > hat feature was introduced in v5.34

    Thanks, I'm feeling stupid now.

    I'm having the newest available Strawberry Perl 5.32 installed and didn't think about the perldoc being even newer.

    > It's not mentioned in perlop, so a doco omission

    I searched for "version" in perlop and there are many mentions of differences to older Perl.

    Not sure if this is always done, but I certainly would have preferred seeing a "(since v5.34)" somewhere.

    And I found the description rather cryptic too.

    • but shows optional blanks inside and adjoining the braces
    shouldn't it rather be "ignores" or "tolerates blanks"?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      shouldn't it rather be "ignores" or "tolerates" whitespace?

      My suggested phrasing would be on "but allows° optional blanks between the braces and the hex value"

      (And whether I said "blanks" or "spaces" or "horizontal whitespace" or "whitespace" would probably depend on whether tests show that it allows only space, or any horizontal space, or any horizontal or vertical space. Like you, I only have Strawberry so limited to 5.32 and cannot test the feature.)

      update: °: Rereading the original, I think they intended that sentence to mean the equivalent of "This second example of the syntax means the same as the example above, but shows the optional blanks that are allowed..."

        The footnote defines "blanks" as tab or space, so "\n" shouldn't be allowed.

        Blanks (tab or space characters) may separate the number from either or both of the braces.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        > update: °: Rereading the original, I think they intended that sentence to mean the equivalent of "This second example of the syntax means the same as the example above, but shows the optional blanks that are allowed..."

        yes, that's what I'm thinking too.

        They probably copy/pasted it from some p5p-discussions or feature requests, and the context got lost.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

      'I searched for "version" ...'

      On the basis that version notes often look like "introduced in 5.nn", I searched for "34": 8 instances found; none relate to this issue.

      '... but shows ... shouldn't it rather be "ignores" or "tolerates" whitespace?'

      I believe that was intended to contrast with the previous line (\x{263A} vs. \x{ 263A }). Depending on device, browser and font, the difference between \x{263A} and \x{ 263A } may not be all that obvious.

      Regardless, a ninth note (e.g. [9] Introduced in v5.34.0.) would add clarity.

      — Ken

        > often look like "introduced in 5.nn", I searched for "34"

        None of my hits for "34" had to do with versions.

        But I searched for "5." leading to 40 hits, only 2 were not referring to version diffs.

        So yes, perldoc normally lists such differences.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        > Regardless, a ninth note (e.g. 9 Introduced in v5.34.0.) would add clarity.

        Normally I'd say a footnote is overkill, but since there is that note

        Note that any escape sequence using braces inside interpolated constructs may have optional blanks (tab or space characters) adjoining with and inside of the braces, as illustrated above by the second \x{ } example.

        every "escape sequence using braces" should better have this as footnote plus "(since v5.34.0)"

        On a side note, this seems to be in analogy how identifiers inside braces are handled

        DB<70> $a = 42 + + + DB<71> p ${ a } + 42 + DB<72> p ${ a } + 42 + DB<73> p "${ a }" + 42 + DB<74>

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery