Running the test directly under the Perl debugger:
And running the same at the command line:DB<1> $x = "a\n"; DB<2> $x = chomp $x; DB<3> print $x 1
So I get 1 under the debugger et 0 at the command line. Isn't it strange?$ perl -E 'my $x = "a\n"; $x = chomp $x; say $x' 0
And, BTW, using another variable solves the issue:
This leads me to believe that doing this:$ perl -E 'my $x = "a\n"; my $y = chomp $x; say $y;' 1
might well be undefined behavior (and should most probably be avoided), just as:$x = chomp $x;
is undefined both in C and in Perl. (And different C compilers actually give different results on the code above, I have tried it once in the past.)$c = ++$c;
In reply to Re: Assigning the result of a chomp to the chomped var itself.
by Laurent_R
in thread Assigning the result of a chomp to the chomped var itself.
by choroba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |