concatenation_weirdness.pl 448 B

1234567891011121314151617
  1. #!/usr/bin/perl
  2. # Weird order of concatenation of variables, when the variables are mutated during concatenation.
  3. # In older versions of Perl, the first statement correctly returns "abc".
  4. # In newer versions of Perl, both statements return incorrect values.
  5. use 5.010;
  6. use strict;
  7. use warnings;
  8. my $x = 'a';
  9. my $y = 'b';
  10. say ($x . $y . ++$y); #=> expected "abc", but got "acc"
  11. say ($x . ++$x); #=> expected "ab", but got "bb"