develooper Front page | perl.perl5.porters | Postings from November 2010

weird or bad?: my $x .= 'x';

Thread Next
From:
Mike O'Regan
Date:
November 16, 2010 15:55
Subject:
weird or bad?: my $x .= 'x';
Message ID:
1289951721.24381.29.camel@moregan
Stumbled across this behavior today in 5.8.8 and 5.10.1.  Some of the
"compound" assignment operators (is there a term for them?) warn and
some don't in a declaration:

perl -w -e 'my $x .= "str"; print "$x\n"'
str

perl -w -e 'my $x *= 2; print "$x\n"'
Use of uninitialized value $x in multiplication (*) at -e line 1.
0

perl -w -e 'my $x |= 1; print "$x\n"'
1

perlop says only that "Assignment operators work as in C.  That is, $a
+= 2 is equivalent to $a = $a + 2...".  That leads me to expect a
warning every time.  Is there a bug or is this just something I don't
understand?

FWIW, the Perl::Critic rule I'm putting together found this type of
construct 10 times in my perl5/5.10.1:

5.10.1/CPAN/FTP.pm: Compound assignment operator line 533
5.10.1/ExtUtils/MM_Any.pm: Compound assignment operator line 1163
5.10.1/ExtUtils/MM_VMS.pm: Compound assignment operator line 639
5.10.1/IPC/Cmd.pm: Compound assignment operator line 922
5.10.1/Object/Accessor.pm: Compound assignment operator line 616
5.10.1/Object/Accessor.pm: Compound assignment operator line 625
5.10.1/Archive/Tar/File.pm: Compound assignment operator line 456
5.10.1/Log/Message/Simple.pm: Compound assignment operator line 214
5.10.1/x86_64-linux/IO/Compress/Gzip.pm: Compound assignment operator
line 238
5.10.1/x86_64-linux/IO/Compress/Gzip.pm: Compound assignment operator
line 249

Mike O'Regan

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About