in reply to Re: pattern match against in-memory file causes odd behavior
in thread pattern match against in-memory file causes odd behavior
It seems in some cases the trailing \0 of the PV is missing (according to Devel::Peek), and in those cases, the regex doesn't match:
use Devel::Peek; open my $fh, '>', \my $memory_file; for (qw(abc def ghi jkl mno)) { print $fh $_; Dump $memory_file; if ( $memory_file =~ m/^(.*)$/ ) { print "==> matched: $1\n" } } __END__ SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abc"\0 CUR = 3 LEN = 8 ==> matched: abc SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdef"\0 CUR = 6 LEN = 8 ==> matched: abcdef SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghi" <--- !! CUR = 9 LEN = 16 SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghijkl"\0 CUR = 12 LEN = 16 ==> matched: abcdefghijkl SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghijklmno"\0 CUR = 15 LEN = 16 ==> matched: abcdefghijklmno
Update: some further testing (with minor modifications) shows that there are also cases, where it does match despite a missing trailing \0. So yes, erratic, at best :)
|
|---|