By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

Want to remove an unwanted charachter from scalar

P: 2
I am reading in a file that has a list that of items. The items I place into a scalar for print but when i do, there is an extra unwanted charachter that shows up at the end of each item. It looks to be some hex charachter. It does not exist in the original file. Is this some sort of charachter set and can I remove it with a substition routine?

I have tried

$item =~ s/\x+$//g;


$item =~ s/[\n+\r+\f+\e+\t+]//g;

but they do not help.

Any help would be great in identifying and removing this. Thanks. -ljs
Apr 21 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 2.5K+
P: 4,059
are you using chomp()? If so the file was probably created on a different operating system and the line endings are differnt than the operating sytem the script is running on. You can try:

$item =~ s/[\r\n]?$//;

see if that helps.
Apr 21 '08 #2

P: 2

Thanks. However, it didn't make a difference.

I think the extra charachter is a <160> or char set for &nbsp. However, even knowing that, I can't seem to get rid of it.

Any ideas that might help?

Apr 22 '08 #3

Expert 2.5K+
P: 4,059
is $item a multiline scalar? In other words, does it have embedded records seperators like newlines in it? If so you can try this:

$item =~ s/[\r\n]?$//m;

If not, I am not sure what else to suggest.
Apr 22 '08 #4

Expert 2.5K+
P: 3,652
You could try getting the item (weird character and all), then capturing the legible portion:

Expand|Select|Wrap|Line Numbers
  1. $item =~ /([A-Za-z]+)/;
  2. $item = $1;
If the item could be multiple words, add spaces - if the item includes numbers, inclue 0-9, etc. etc.
Apr 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.