468,294 Members | 1,786 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,294 developers. It's quick & easy.

Want to remove an unwanted charachter from scalar

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;

and

$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
4 1371
KevinADC
4,059 Expert 2GB
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
KevinADC,

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?

Thanks.
Apr 22 '08 #3
KevinADC
4,059 Expert 2GB
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
Ganon11
3,652 Expert 2GB
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.

Similar topics

11 posts views Thread by Tony Johansson | last post: by
5 posts views Thread by Bob Stearns | last post: by
10 posts views Thread by pamelafluente | last post: by
4 posts views Thread by Magnus Warker | last post: by
reply views Thread by Michel Esber | last post: by
3 posts views Thread by Barkingmadscot | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.