[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<>], who wrote in article <>:
> Also sprach Ilya Zakharevich:
>
> ><>], who wrote in article <>:
> >> For testing what the raw string looks like after the bitwise-and, you
> >> can use:
> >
> > Is not it much easier to parse the output of Devel:
eek, and read the
> > PV by unpack()?
>
> No, it wasn't for me. 
>
> Can you give an example how to do it with unpack? I feel the 'P'
> template is needed but I never know how to use that one.
You are right: I thought that one can easily get the result of Dump
into a variable. Probably not easy... So to do it without fork()
would not be easy:
#!/usr/bin/perl -wl
use strict;
use Devel:

eek;
# Prepare what to inspect
my $a = 'aa';
$a &= 'a';
defined (my $pid = open my $p, '-|') or die "Can't fork() to self-pipe: $!";
if ($pid) { # parent
my $out;
{
local $/;
$out = <$p>;
close $p or die;
}
# Parse output of Dump using the expected format below:
my ($addr, $len) = ($out =~ m/
^ \s+ PV \s* = \s* (0x[[

digit:]]+) \b
.*?
^ \s+ LEN \s* = \s* (\d+) \b
/xsm);
die "unexpected format of output of Dump" unless $addr and $len;
my $buff = unpack "P$len", pack 'J', hex $addr;
print ord for split //, $buff;
} else { # kid
open STDERR, '>&', \*STDOUT or die;
Dump $a;
###SV = PV(0x40c64) at 0x40a24
### REFCNT = 1
### FLAGS = (PADBUSY,PADMY,POK,pPOK)
### PV = 0x42020 "a"
### CUR = 1
### LEN = 3
}
__END__
> What are those two bugs you mentioned? For me the real bug is that an
> 'impossible' string value can be constructed thus.
Well, the REx engine operates in terms of start-of-string and
end-of-string. It should not read behind.
Moreover, IMO, it is important to support variables which are not
\0-terminated as wide as possible. E.g., this way one could do
substr() with copy-on-modify semantic.
> I would expect:
>
> ('aa' & 'a') eq "a\0"
>
> Taking (b) into account, the smaller string should be padded with '\0'
> which, on bit-wise ANDing, should yield '\0'.
.... And, since this \0 comes from "extrapolated" values, it should be
"deextrapotated"; in other words, stripped.
> There's another oddity:
> $ perl -MDevel:
eek -e 'my $a = 'aa'; $a &= 'a'; Dump($a)'
> SV = PV(0x814ce90) at 0x814cc6c
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,POK,pPOK)
> PV = 0x815d628 "a"
> CUR = 1
> LEN = 3
We know this already...
> $ perl -MDevel:
eek -e 'my $a = 'aa' & 'a'; Dump($a)'
> SV = PV(0x814cf20) at 0x814cc6c
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,POK,pPOK)
> PV = 0x815c0e8 "a"\0
> CUR = 1
> LEN = 2
Here 'aa' & 'a' is a temporary; most probably not \0-terminated. Now
the assignment operator fills $a from the values in the temporary; as
any well-behaved Perl operator, it does not care whether there is a
trailing \0. So it does not know that the temporary is "buggy".
Hope this helps,
Ilya