Salvor has asked for the wisdom of the Perl Monks concerning the following question:
in a Perl training (I am the trainer) we discovered some odd(?) behavior of the chomp() function.
I know, of course, that it returns the number of removed line-ends, and so it does:
But to demonstrate wrong usage of chomp(), I triedmy $line = "hello\n"; my $x = chomp $line; print $x; # prints "1"
my $line = "hello\n"; $line = chomp $line; print $line; # prints "0"!
What am I missing here? Why doesn't it just overwrite the content of $line with "1"?
I tested it on Linux and Windows/ActivePerl with newer Perls (5.20 I think). Same behaviour.
Perhaps someone could enlighten me/us? Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd behaviour of chomp()
by dave_the_m (Monsignor) on Oct 20, 2015 at 10:58 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |