in reply to Re: Regarding B::Deparse
in thread Regarding B::Deparse


That was interesting,

It turns out that B::Deparse was putting in "\n"s into the string that was declared at the top of It Came From the Crypt. It then thought that everything would be alright if it changed the next substitution to get rid of them, except that it wasn't. If you run B::Deparse and shove the contents into a file, then to run that you need to modify the first substitution so that it does nothing to the poor "\n"s.

#change this: $u=$q=~s/\n\s//xg && -2; #to this $u=$q=~s/\s//xg && -2;
That seems to do it for me at least (running perl 5.6 on a redhat box). Anyone else? Also, why does Perl insert the carriage returns and then change a regex to deal with it? That seems odd...

jynx

Replies are listed 'Best First'.
Re: Re: Re: Regarding B::Deparse
by blakem (Monsignor) on Oct 20, 2001 at 01:41 UTC
    Very interesting indeed. It looks like B::Deparse doesn't fully understand the magic associated with the /x regex modifier. With /x, a literal \n and the two character sequence '\n' are not actually equivalent. B::Deparse isn't making that distinction.

    Below, the second regex is the result of running the first one through B::Deparse. As this example shows, they are not the same.

    #!/usr/bin/perl -wT use strict; my $v1 = my $v2 = "abcdef"; $v1 =~ s/c d//x; # original pattern: literal \n is gobbled by /x # equivalent to the non-x: s/cd//; $v2 =~ s/c\nd//x; # deparsed version: interpolated "\n" is not touch +ed by /x # equivalent to the non-x: s/c\nd//; print "V1 = '$v1'\n"; print "V2 = '$v2'\n"; =OUTPUT V1 = 'abef' V2 = 'abcdef'

    -Blake

      I've done a lot of work on B::Deparse since perl 5.6 came out, and the development snapshots of perl have a lot of fixes which aren't in the version that comes with 5.6.

      Unfortunately, B::Deparse is very intimate with the internals of the interpreter, and so you can't upgrade it on its own. But if you're feeling experimental, try downloading the latest development snapshot of perl from here. Go for the one with the biggest number - it indicates the patchlevel. (The latest development snapshot is also called bleadperl, because it's on the leading/bleeding edge.)

      And yes, I did fix the /x bug. Your example works fine with bleadperl. Of course these fixes will all be in perl 5.8 when it's released.