dsrZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a parser script which reads from a log file, which is in Wide Character format. So the string is read with spaces between the characters, i.e "T A L K". And because of that none of my regular expression or parking works? How do I convert the string/ling from "T A L K" to "TALK"?
  • Comment on Reading wide character string from a file

Replies are listed 'Best First'.
Re: Reading wide character string from a file
by ikegami (Patriarch) on Oct 22, 2008 at 21:31 UTC

    "Wide Character format" most likely means it's encoded using UCS-2le. You're treating it as if it was encoded using iso-latin-1. Just decode it.

    open(my $log_fh, '<:encoding(UCS-2le)', $log_qfn) or die("Can't open log file \"$log_qfn\": $!\n");
      Thanks a bunch, ikegami, this worked!! :)
Re: Reading wide character string from a file
by Lawliet (Curate) on Oct 22, 2008 at 21:27 UTC

    How many spaces are there between each word? If there are more than one, you can simply s/ //; - I think.

    Update: Oh, whoops. I meant s/(\w*) (\w+)/$1$2/g. Err, that is what I saw in my head, just not what I typed. Thanks, JadeNB.

    I'm so adjective, I verb nouns!

    chomp; # nom nom nom