On 2007-03-29 13:15, Chris <> wrote:
> Thanks for suggestion and for making me aware of unpack!
There
> is a rogue carriage return (0xd) in the string that isn't appearing in
> the other strings, even though the file characteristics are the same
> as far as the naked eye can see between all my files, this is the only
> one with that strange character at the end. chomp() doesn't seem to
> get rid of it either.
Chomp only removes $/, which is usually "\n", not "\r".
> Is there something I can do to deal with this situation?
You probably want to ignore any whitespace at the end of the line, so
you could change your pattern from:
$searchTag = "^#include\\s*(.*)";
to
$searchTag = "^#include\\s*(.*?)\\s*$";
This would not only get rid of the \r, but also of any spaces or tabs at
the end of the line (which normally aren't visible to the naked eye
either).
> I've tried retyping the string by hand in the file, but it
> doesn't seem to be going away for some reason.
Your editor is probably detecting the MS-DOS line endings and acting
accordingly. It should have a way to change this. For example, in vim,
you can switch to unix-style line endings with
:set fileformat=unix
and then just save the file. There are also utilities like dos2unix
which do this, or you can write a simple one-line perl script ...
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | |
| the circumlocutions of bureaucrats.
__/ |
http://www.hjp.at/ | -- Charlton Wilbur in clpm