Re: Bug in &= (bitwise or)
- From: Abigail <abigail@xxxxxxxxxx>
- Date: 31 Oct 2005 22:29:10 GMT
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";
.
- References:
- Bug in &= (bitwise or)
- From: Anno Siegel
- Bug in &= (bitwise or)
- Prev by Date: Re: using perl to print yesterday's date, but with formatting options ?
- Next by Date: Re: Perl gethostbyname
- Previous by thread: Re: Bug in &= (bitwise or)
- Next by thread: freeze panes in excel without using a module
- Index(es):
Relevant Pages
|