dirtdart has asked for the wisdom of the Perl Monks concerning the following question:
Not surprisingly, it doesn't work. So I do some reading, peruse perluniintro, perlunicode and various other documentation and find that what I REALLY need to do is:open FILE, $myfile while(<FILE>) { if(/Information Store/i) { $found = 1; last; } }
Still doesn't work. Inside the while loop, I place a print "$_\n" and find that each line is printed with what appear to be spaces between each letter. This is the case whether I use the first open method or the second. So, just to see what Perl thinks, I insert utf8::is_unicode($_) in the while loop. Returns 1 every time no matter how I open the file. Obviously Perl believes this to be a Unicode string. I try using utf8::decode on the string to see what it turns into, only to find out that although the function returns 1 for success, the string is completly unchanged. So, in desparation, I attempt to turn the string into an array of bytes using unpack. Both unpack "U*" and unpack "C*" return the exact same character array, and in both, the "space" between characters is reported as having a value of 48. According to the ASCII character charts, this should print as a 0 (zero). Now I'm completly dumbfounded. I don't care if Perl thinks this is a Unicode string, ASCII string, EBCDIC string, or anything else it wants. I just want to be able to use a regular expression to find certain data within this string and I can't. Does anyone have any advice on how to get this accomplished?open FILE, "<:utf8", $myfile while(<FILE>) { if(/Information Store/i) { $found = 1; last; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unicode and text files
by davorg (Chancellor) on Oct 12, 2006 at 13:35 UTC | |
by dirtdart (Beadle) on Oct 12, 2006 at 13:49 UTC | |
by Hue-Bond (Priest) on Oct 12, 2006 at 14:02 UTC | |
by dirtdart (Beadle) on Oct 12, 2006 at 14:05 UTC | |
by Hue-Bond (Priest) on Oct 12, 2006 at 17:44 UTC | |
| |
by davorg (Chancellor) on Oct 13, 2006 at 07:46 UTC | |
by graff (Chancellor) on Oct 12, 2006 at 21:14 UTC | |
|
Re: Unicode and text files
by Melly (Chaplain) on Oct 12, 2006 at 13:32 UTC | |
by dirtdart (Beadle) on Oct 12, 2006 at 13:41 UTC | |
|
Re: Unicode and text files
by Errto (Vicar) on Oct 13, 2006 at 02:51 UTC |