
lukdk
Novice
Aug 27, 2012, 5:19 AM
Post #1 of 5
(634 views)
|
|
regular expression, white spaces
|
Can't Post
|
|
Hello, I'm trying to remove the white spaces in front and after a variable. The variable comes from a file which needs to be read. The following code seems to work at first: sub trim{ my $str=shift; return "" if !defined $str; $str=~s/^\s+//; $str=~s/\s+$//; return ($str); } However, when I try this code, it doesn't remove anything. I tried to open the input file in a text editor and saw white spaces in front and after the string. When I tried in a dos box "type input.txt" I noticed all the white spaces got replaced by "á" signs. I'm guessing I'll need to use another expression, the problem is I don't know what to match for. How can I discover that hidden character that seems like a white space, but isn't one after all?
|