in reply to Assigning the result of a chomp to the chomped var itself.
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Assigning the result of a chomp to the chomped var itself.
by Anonymous Monk on Nov 26, 2014 at 20:02 UTC |