A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Perl/perl5/issues/22412 below:

split bitwise-assignment operators (`&=`, `&.=`, etc) don't return lvalues · Issue #22412 · Perl/perl5 · GitHub

Description
Assignment operators (like = itself, but also += or >>=) are supposed to return their left operand as an lvalue, which can then be further modified within the same expression. The old combined numeric/string bitwise assignment operators do this, but the new(er) split numeric and string bitwise operators (as provided by use feature qw(bitwise)) do not.

Steps to Reproduce

$ perl -wle '$_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle '$_ = "HI"; ($_ |= "") ^= " " x 2; print'
hi
$ perl -wle 'use feature qw(bitwise); $_ = 1; ($_ |= 9) ^= 4; print'
Can't modify numeric bitwise or (|) in numeric bitwise xor (^) at -e line 1, near "4;"
Execution of -e aborted due to compilation errors.
$ perl -wle 'use feature qw(bitwise); $_ = "HI"; ($_ |.= "") ^.= " " x 2; print'
Can't modify string bitwise or (|.) in string bitwise xor (^.) at -e line 1, near "2;"
Execution of -e aborted due to compilation errors.

Expected behavior

$ perl -wle '$_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle '$_ = "HI"; ($_ |= "") ^= " " x 2; print'
hi
$ perl -wle 'use feature qw(bitwise); $_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle 'use feature qw(bitwise); $_ = "HI"; ($_ |.= "") ^.= " " x 2; print'
hi

v5.40.0


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4