Mailing List Archive

Data::Dumper does not show tab in regex as \t
If a regex contains an actual tab, Data::Dumper shows it as a tab rather
than \t.
Is that intentional?    AFAIK replacing actual tab with \t in a regex
should produce the same result.

echo -e 'perl -MData::Dumper -wE "say Dumper(qr/AAAA\tBB/)"' | sh
$VAR1 = qr/AAAA    BB/u;

An actual tab, of course, looks like spaces to humans. Could/should D::D
output \t instead?

 -Jim
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
On Fri, 14 Jul 2023, 21:56 Jim Avera, <jim.avera@gmail.com> wrote:

> If a regex contains an actual tab, Data::Dumper shows it as a tab rather
> than \t.
> Is that intentional? AFAIK replacing actual tab with \t in a regex
> should produce the same result.
>
> echo -e 'perl -MData::Dumper -wE "say Dumper(qr/AAAA\tBB/)"' | sh
> $VAR1 = qr/AAAA BB/u;
>
> An actual tab, of course, looks like spaces to humans. Could/should D::D
> output \t instead?
>

I'd expect it to output the pattern that was compiled, so if it was
compiled with \t I'd expect it to be preserved, and if it was compiled as
the codepoint I'd expect it to be preserved also. So yeah, this seems like
a bug, but I'm not 100% certain, I'm on my phone and haven't dug into the
details before writing this.

Yves

>
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
Op 14-07-2023 om 23:26 schreef demerphq:
>
>
> On Fri, 14 Jul 2023, 21:56 Jim Avera, <jim.avera@gmail.com> wrote:
>
> If a regex contains an actual tab, Data::Dumper shows it as a tab
> rather
> than \t.
> Is that intentional?    AFAIK replacing actual tab with \t in a regex
> should produce the same result.
>
> echo -e 'perl -MData::Dumper -wE "say Dumper(qr/AAAA\tBB/)"' | sh
> $VAR1 = qr/AAAA    BB/u;
>
> An actual tab, of course, looks like spaces to humans.
> Could/should D::D
> output \t instead?
>
>
> I'd expect it to output the pattern that was compiled, so if it was
> compiled with \t I'd expect it to be preserved, and if it was compiled
> as the codepoint I'd expect it to be preserved also. So yeah, this
> seems like a bug, but I'm not 100% certain, I'm on my phone and
> haven't dug into the details before writing this.


I'ld say you arguing opposite points. Jim is saying an actual tab
codepoint should translate to '\t' when Dumping(), while Yves is saying
it should roundtrip to whatever it actually, exactly was on input.


Or do I misunderstand?


M4
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
On Sat, 15 Jul 2023, 10:13 Martijn Lievaart via perl5-porters, <
perl5-porters@perl.org> wrote:

> Op 14-07-2023 om 23:26 schreef demerphq:
>
>
>
> On Fri, 14 Jul 2023, 21:56 Jim Avera, <jim.avera@gmail.com> wrote:
>
>> If a regex contains an actual tab, Data::Dumper shows it as a tab rather
>> than \t.
>> Is that intentional? AFAIK replacing actual tab with \t in a regex
>> should produce the same result.
>>
>> echo -e 'perl -MData::Dumper -wE "say Dumper(qr/AAAA\tBB/)"' | sh
>> $VAR1 = qr/AAAA BB/u;
>>
>> An actual tab, of course, looks like spaces to humans. Could/should D::D
>> output \t instead?
>>
>
> I'd expect it to output the pattern that was compiled, so if it was
> compiled with \t I'd expect it to be preserved, and if it was compiled as
> the codepoint I'd expect it to be preserved also. So yeah, this seems like
> a bug, but I'm not 100% certain, I'm on my phone and haven't dug into the
> details before writing this.
>
>
> I'ld say you arguing opposite points.
>
We aren't arguing. Jim asked what should happen, and I replied wearing my
"regex engine expert" hat and said what I think should happen, with caveats.

Jim is saying an actual tab codepoint should translate to '\t' when
> Dumping(),
>
Jim gave an example where the pattern fed to a qr// included \t but which
DD output as a codepoint. He then asked whether that was correct.

while Yves is saying it should roundtrip to whatever it actually, exactly
> was on input.
>

Right. My perspective comes from the fact that escapes in a pattern are not
exactly equivalent to the codepoint that they represent in a double quoted
string. (Consider the hex version of | is not an alternation symbol inside
a qr//) It is up to the regex engine to decode them properly. Thus I think
when this pattern in a qr// is serialized it should not be converted to the
codepoint.

> Or do I misunderstand?
>

If you do it seems only that there is a dispute here, where I see a
question followed by a mostly concurring answer. I suspect that possibly
you have the impression the rules of interpolation in a qr// are the same
for a qq// when in fact they are not.

Cheers
Yves

>
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
Op 15-07-2023 om 10:55 schreef demerphq:
>
>
> Jim is saying an actual tab codepoint should translate to '\t'
> when Dumping(),
>
> Jim gave an example where the pattern fed to a qr// included \t but
> which DD output as a codepoint. He then asked whether that was correct.
>

AFAICS, he fed an actual TAB codepoint, not '\t'. And wants that
translated to '\t' on output, because an actual tab on output can be
confused for spaces.


M4
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
On Sat, 15 Jul 2023, 11:00 Martijn Lievaart via perl5-porters, <
perl5-porters@perl.org> wrote:

> Op 15-07-2023 om 10:55 schreef demerphq:
>
>
>
> Jim is saying an actual tab codepoint should translate to '\t' when
>> Dumping(),
>>
> Jim gave an example where the pattern fed to a qr// included \t but which
> DD output as a codepoint. He then asked whether that was correct.
>
>
> AFAICS, he fed an actual TAB codepoint, not '\t'. And wants that
> translated to '\t' on output, because an actual tab on output can be
> confused for spaces.
>
Ah, I missed the impact of the echo -e. My apology for misunderstanding.

echo -e 'perl -MData::Dumper -wE "say Dumper(qr/AAAA\tBB/)"' | sh
$VAR1 = qr/AAAA BB/u;


Then no, I don't think it should turn the codepoint into \t for the reason
I stated. In regex pattern syntax \t is an escape that represents a tab,
not a literal tab. Unlike in qq// constructs. If you feed in a literal tab
you should get one back.

Cheers,
Yves
Re: Data::Dumper does not show tab in regex as \t [ In reply to ]
Op 15-07-2023 om 12:51 schreef demerphq:
> Then no, I don't think it should turn the codepoint into \t for the
> reason I stated. In regex pattern syntax \t is an escape that
> represents a tab, not a literal tab. Unlike in qq// constructs. If you
> feed in a literal tab you should get one back.
>
>

FWIW, I agree (although I can envision a flag that can control this
behavior).


M4