Chomp behaving strangely

I've an array of strings with some elements which have a newline character at the end. I tried removing the new line character by looping over the array and chomping the element. But instead of removing the \n the whole element is removed. Same thing happens when i do a s/\n// or a tr/\n// can anybody tell me if i'm missing something here. Thanks in advance.
PerlNewBieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

burtdavCommented:
# Sounds weird. The best way to do this should be:
chomp @a;
0
jmcgOwnerCommented:
The situation you're describing is not how Perl works. Perhaps if you showed us your code, we could give you a better idea of what's going on that is not working quite the way you expect it to.

Is it possible that you have elements with a carriage return at the end? This can sometimes cause things to appear quite strange on your screen. The chomp operator would not remove the \r if it thought the current line termination was just \n.
0
burtdavCommented:
# If that's the case, this should do the trick.
# Set default record separator to CR-LF (rather than default LF)
$/ = "\r\n"
# Before chomping the array
chomp @a;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

siliconiteCommented:
try
chop whatever;
0
jyokumCommented:
you're chomping the array instead of the elements in the array, try this

foreach(@a){
  chomp $_;
}
0
burtdavCommented:
TIMTOWTDI. (chomp @a) is valid, and more consise than your suggestion, jyokum. Try it =)
0
jyokumCommented:
thanks for the info. consider me ignorant but what's TIMTOWTDI
0
burtdavCommented:
It's the Perl motto - there is more than one way to do it. It's important to remember, because there is; indeed, usually are, many more.

Also note that many Perl functions process scalar and list parameters differently. chop and chomp apply themselves to each element in the list; the return value changes, too, depending.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.