Pages

6/10/2005

Perl::Whitespace


$line =~ s/^\s+//; is supposed to get rid of all whitespace characters at the beginning of a line. I have been messing around for white a bit now scratching my head about why this is not working for me.

Finally I open the text file "as binary" to see the HEX codes for each character and I find that the "spaces" at the beginning of this line of my data file are NULL, that is "ASCII code" = zero.

So, NULL must not be defined in Perl as "whitespace." I assume it will only match the "blank" characters that have their own special escape character like \t \n and "space" (ASCII 32, HEX 20.)

Well I replaced s/^\s+//; with s/^\x00+//; and life is now good.....

If you read this (and I know at least a few of you are out there) leave me a comment if you can confirm what Perl defines as "whitespace" when matching on \s.

No comments: