Front page | perl.perl5.porters |
Postings from February 2012
Re: [perl #58608] Data::Dumper and slashes within qr
Thread Previous
|
Thread Next
From:
demerphq
Date:
February 4, 2012 02:21
Subject:
Re: [perl #58608] Data::Dumper and slashes within qr
Message ID:
CANgJU+WrLxLEm-_5rfKs4jOQLYFzAg2_db36+4b4azcpnDUoZA@mail.gmail.com
On 4 February 2012 08:43, Father Chrysostomos via RT
<perlbug-followup@perl.org> wrote:
> On Tue Jan 10 01:08:49 2012, ikegami@adaelis.com wrote:
>> On Mon, Jan 9, 2012 at 10:56 PM, Adam Thomason <perlbug-
>> followup@perl.org>wrote:
>>
>> > The escaping code on line 376 was introduced in 4ab99479, without
>> > particular
>> > comment to its necessity. Removing it doesn't break DD's test suite,
>> but
>> > it's quite possible it breaks something else, perhaps an older perl
>> which
>> > stringifies regexes differently.
>> >
>>
>> Some escaping of "\" is needed even on latest Perl.
>>
>> >perl -MData::Dumper -E"$r=qr(\/); say $r; print Dumper($r);"
>> (?^u:\/)
>> $VAR1 = qr/(?^u:\\/)/; # XXX
>>
>> >perl -MData::Dumper -E"$r=qr(/); say $r; print Dumper($r);"
>> (?^u:/)
>> $VAR1 = qr/(?^u:\/)/; # Ok, but would break if you remove the
>> escaping.
>>
>> Dumper needs to add "\" in front of "/" unless its preceded by an odd
>> number of "\":
>>
>> $pat =~ s,/,\\/,g;
>>
>> Needs to be something like
>>
>> $pat =~ s,(?<!\\)(?:\\\\)*\K/,\\/,g;
>
> I somehow missed this message. That’s five times the speed of the
> pattern I used in de5ef703c. But unfortunately it won’t work on older
> perls. I doubt it’s worth the complexity of conditionally compiling a
> regexp, as the XS version is used mostly.
My 5 cents from the p5p chat room.
(11:13:40 AM) demerphq: i dont really have time to write it up
properly, but this business of DD escaping regexes.
(11:13:46 AM) demerphq: I think there must be a better way
(11:13:50 AM) demerphq: via the re.pm module
(11:14:39 AM) demerphq: the proposed patch is implicitly broken as it
assumes that you can/must escape in a particular way
(11:14:47 AM) demerphq: what happens if the qr// is for a different engine?
11:15
(11:15:31 AM) demerphq: imo each engine should produce a "turn this
pattern into code" function
(11:16:29 AM) demerphq: anyway. the other thing is DD does not use
re's code to get the pattern
(11:16:35 AM) demerphq: which means it wont round trip qr's anyway
(11:16:42 AM) demerphq: as its going to (?:...) them each time
(11:16:53 AM) demerphq: it has to use regexp_pattern() in list context iirc.
(11:17:16 AM) demerphq: re:regexp_pattern
(11:19:27 AM) demerphq: http://perldoc.perl.org/re.html#regexp_pattern(%24ref)
(11:19:28 AM) dipsy: [ re - perldoc.perl.org ]
See also how and what DDS does (maybe wrong) for this case.
Yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"
Thread Previous
|
Thread Next