Re: Bug in &= (bitwise or)



Anno Siegel (anno4000@xxxxxxxxxxxxxxxxxxxxxxx) wrote on MMMMCDXLIV
September MCMXCIII in <URL:news:dk5rri$anu$1@xxxxxxxxxxxxxxxxxxxxxxxxx>:
$$ I am observing this strange behavior:
$$
$$ # prepare a string
$$ my $str = 'aa';
$$ $str &= 'a'; # shorten it
$$ print "str: $str\n"; # a single "a" as expected
$$
$$ # $str = "$str"; # this heals the defect (if any)
$$
$$ # something is wrong, though
$$ die "Ha!\n" unless $str =~ /a+$/; # this dies!
$$
$$ The pattern should, of course, match. Similar patterns, like /a$/ and
$$ /a+/ do match, but /a+$/ isn't recognized. Copying the string into itself
$$ normalizes the behavior. "use bytes" makes no difference.
$$
$$ Whether the bug (or am I missing something?) is in &= or the regex
$$ engine (gasp) is anyone's guess. My money is on string-truncation
$$ by &=. It would be rarely-exercised code, other bitwise operations
$$ don't shorten.


I think &= is broken:

use Devel::Peek;

my $str1 = "aa"; $str1 &= "a";
my $str2 = "a";
my $str3 = "aa" & "a";

Dump $str1;
Dump $str2;
Dump $str3;

__END__
SV = PV(0x8183010) at 0x8182ca8
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x818a690 "a"
CUR = 1
LEN = 3
SV = PV(0x8183154) at 0x8182cf0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x818c0f8 "a"\0
CUR = 1
LEN = 2
SV = PV(0x8182ff8) at 0x81821e0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x818c0f8 "a"\0
CUR = 1
LEN = 2
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
.



Relevant Pages

  • Bug in &= (bitwise or)
    ... I am observing this strange behavior: ... # prepare a string ... The pattern should, of course, match. ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Bug in &= (bitwise or)
    ... > I am observing this strange behavior: ... According to Devel::Peek, string truncation results ... FLAGS = ... CUR = 2 ...
    (comp.lang.perl.misc)
  • Re: Predicting the Future and Kolmogorov Complexity
    ... Predictability is based on the pattern itself. ... addition to the string. ... For any prediction scheme, there are computable strings that show no ... Out of this hole comes a ~2 cm blue marble followed by a red ...
    (talk.origins)
  • Re: macro for parsing text
    ... SUB will remove from any cell selected the pattern as you described (i.e. ... Dim c As Range ... Dim Temp As String ... Dim colMatches As MatchCollection ...
    (microsoft.public.excel.programming)
  • Re: macro for parsing text
    ... SUB will remove from any cell selected the pattern as you described (i.e. ... Dim c As Range ... Dim Temp As String ... Dim colMatches As MatchCollection ...
    (microsoft.public.excel.programming)