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

i am trying to use Win32::Gui to display data from a file in a textarea. Something strange happens to the text, though. Code is similar to following;
open FILE,"</test"; for(<FILE>){ $Text .= "$_\x012"; } close FILE; $Inputfield = $W2->AddTextfield( -name => "input", -left => 5, -top => 1, -text => "$Text", -width => 280, -height => 170, -foreground => [0,0,0], -background => [255,255,255], -tabstop => 1, -multiline => 1, -wrap=>1 );
the text prints as follows:
this is only a testthis is only a testthis is only a test
instead of:
this is only a test this is only a test this is only a test
Any ideas why? Thank you in advance.

Replies are listed 'Best First'.
Re: Win32::Gui Textarea question
by halley (Prior) on May 14, 2003 at 03:06 UTC

    In non-Unicode settings, I believe Windows' multi-line edit controls internally use "\x0D\x0A" bytes for hard line breaks, and "\x0D\x0D\x0A" for word wraps.

    If you have to deal with a certain platform's byte sequences for line breaks, don't just use the semantic names "\n" or "\r", but get specific with hex or octal codes. "\n" should be read as "whatever newline this platform *usually* likes."

    --
    [ e d @ h a l l e y . c c ]

      Thank you halley, that was exactly the answer I was looking for. If I could ++ you I would.
Re: Win32::Gui Textarea question
by The Mad Hatter (Priest) on May 14, 2003 at 00:45 UTC
    I don't have a windows machine to test on, but have you tried using \r\n instead of just \n? I don't know what \x012 is, but methinks you should probably replace
    $Text .= "$_\x012";
    with
    $Text .= "$_\r\n";
    or
    $Text .= "$_\n";
    and see what the results are.

      "\x012" is two characters, the (hex) escape "\x01" (which has the same value as chr(0x01)) and the plain character "2".

      In this context, I suspect it is a typo for "\012", which would be an octal escape, the same as chr(012), the ASCII LF character.

      Hugo
Re: Win32::Gui Textarea question
by Anonymous Monk on May 14, 2003 at 01:47 UTC
    my mistake. line shoud be:
    $Text .= "$_\n";
    It still, however, does not print properly with \n or \r\n. the results are the same.