Safe Chopping with Chomp
Rather than just wantonly remove the last character regardless of whatever it is,
without a care in the world, just simply consigning the poor little thing to the Great Bit
Bucket in the Sky, you can remove the last character only if it is a newline with chomp :
chomp ($name=<STDIN>);
At this point the perl gurus are screaming "I found an error !". Well, chomp doesn't always remove the last character if it
is a newline but if it doesn't, you have set a special variable, namely $/ , to something different. I presume that if you do
set $/ you know what it does. It is explained
later in this very document. Of course, being a good pupil, you wouldn't experiment with
the unknown, blindly changing things just for the hell of it to see what happens.
If you don't, you'll never learn anything useful.