in reply to Regex for replacing hidden character: « and L

Almost always the answer to the sort of probelm involves line end sequence characters. « is character 171 (0xab) and it is not at all clear to me how the normal line end characters (\n and \r) could mutate into that unless something is translating all unprintable characters into that. Assuming that to be the case:

Perl is expecting the line seperator character sequence to be a new line character ("\n"). If the application you are running is generating output for Windows or a Mac, or for various other purposes (network output for example), the line end may be a sequence of "\r\n" (for Windows and network) or "\r" for a Mac. I think it most likely that the odd character you are seeing is a "\r" which you could handle as:

$tm =~ s/[L\r]//;

However I doubt that you really want an 'L' in there so most likely what you want is:

$tm =~ s/\r//;

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Regex for replacing hidden character: « and L
by virtualsue (Vicar) on Mar 18, 2006 at 06:30 UTC
    If we ever see a day when there are line ending incompatibility occurring even between different versions of linux, ACK! In this case, it looks as though the same script is being run on multiple linux machines, but the odd character business is being seen on the box on which the command is run. If so, I sure hope that is not a newline problem. In neversaint's script he splits on whitespace and $tm is at the beginning of the thing being split, so this might make you wonder. :)

    neversaint, if you always have to remove the last character of $tm, maybe you should just chop $tm rather than fuss with removing the char via s///.

    Update: wording change in first paragraph