Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Notepad: I'm seeing squares.

by emilford (Friar)
on Nov 23, 2005 at 14:53 UTC ( #511120=perlquestion: print w/replies, xml ) Need Help??

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

Open the file in Notepad and it's flooded with little squares. I'm using Perl on the Unix side to generate a txt file that is then downloaded on a Windows box. Most every application recognizes the line ends, but I'm still having difficulty with Notepad.

I've read through many of the threads on this, but am still not certain what to do. I've tried to swap \n for \r\n, but no luck. I tried to swap \n for \cM, but still no luck.

What else should I try?

Replies are listed 'Best First'.
Re: Notepad: I'm seeing squares.
by Mutant (Priest) on Nov 23, 2005 at 15:29 UTC
    \r\n should work for Windows. The problem could be in the way you're transferring the file between the two systems.
      This is a good point.

      If you are using \r\n and still seeing the squares, here is what I would recommend:

      Create the file, copy it to the Windows box, then transfer the same file back to the *nix environment. Once back in the *nix environment, open it with a simple editor like vi(m) or something similar. In most cases, you will see any wierd control/Windows/Unix characters that might have gotten mixed in while transferring.

      If nothing shows up, I would simply make sure you are using \r\n

      print map{$_.' '}grep{/\w+/}@{[reverse(qw{Perl Code})]} or die while ( 'trying' );
        While that might work, I don't have the liberty of copying the file back and forth between environments. I need to provide the user with a downloadable version of the file that will look as it should (i.e. - no squares).
Re: Notepad: I'm seeing squares.
by ikegami (Patriarch) on Nov 23, 2005 at 15:47 UTC
    I've tried to swap \n for \r\n

    Like people have said, this should have worked. Notepad expects \r\n for line ends. Either 1) your file didn't use \n for line ends originally, or 2) you convertion code has a bug (and you probably ended up with \r\r\n).

    A simple one liner to convert from \n to \r\n (when run from a Windows machine) is:

    perl -pe1 infile > outfile
    The above is similar to the following code:
    open(my $fh_in, '<', $file_in) or die("Unable to open $file_in: $!\n"); open(my $fh_out, '>', $file_out) or die("Unable to create $file_out: $!\n"); print $fh_out $_ while <$fh_in>;
Re: Notepad: I'm seeing squares.
by mikeock (Hermit) on Nov 23, 2005 at 15:47 UTC
    If you are ftping the files from a *nix box, turn on binary first.
Re: Notepad: I'm seeing squares.
by marto (Cardinal) on Nov 23, 2005 at 15:09 UTC
    Hi emilford,

    On Windows I use notepad++ as a replacement for notepad. If downloading this is an option you may want to check it out. Are you able to use the unix2dos command to convert the file(s) before tranfering them?

    Hope this helps.

      Thanks for the suggestion, but I need a Perl solution.
Re: Notepad: I'm seeing squares.
by pboin (Deacon) on Nov 23, 2005 at 15:48 UTC

    You've got a bad assumption somewhere. "\r\n" on a unix-y perl will positively give you valid DOS carriage control. Open your file with a hex editor and you'll see something other than hex "0d0a" there for sure. That's the best way to shoot your problem.

      I viewed the file and the double squares do equate to 0D0A. That's what it's supposed to be right?
        Yes. x'0D0A' is valid DOS carriage control. But notepad shouldn't be putting up boxes for it. Any chance you can post your text file somewhere so others can test it? Or, maybe you can reproduce the problem w/ non-sensitive data.
Re: Notepad: I'm seeing squares.
by Anonymous Monk on Nov 23, 2005 at 15:04 UTC
    I think Wordpad handles this correctly.
      It does, but I can't rely on everyone knowing that. Even if only one person attempts to open in Notepad and sees a bunch of squares and mashed together text, that's one too many in this case.


        the "\r\n" should work for you.. it does for me (TM). As for the notepad/wordpad... save it in the extension of ".wri" which is assocated with wordpad by default.

        hope this helps

        Jason L. Froebe

        Team Sybase member

        No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: Notepad: I'm seeing squares.
by swampyankee (Parson) on Nov 23, 2005 at 18:04 UTC

    I'm probably going to get massive downvotes for this, but those little boxes, in my experience, mean that there are no glyphs associated with the character codes. (added in edit) Incorrect end-of-line markers (end of addition) That typically result in the text being squished onto one line; if you're "flooded with little squares" I don't think that the problem is the end-of-line markers.

    Have you tried a) changing the font in Notepad, so see if the little boxes go away, b) opening the document in another editor see if the problem is unique to Notepad or c) explicitly creating the document in UTF-8?

    Edited to make the 2d sentence comprehensible


Re: Notepad: I'm seeing squares.
by Moron (Curate) on Nov 23, 2005 at 16:19 UTC
    Another thought - what about opening it with OpenOffice, although you may still need to do a unixtodos on it first as marto suggested.


    Free your mind

Re: Notepad: I'm seeing squares.
by Moron (Curate) on Nov 23, 2005 at 15:31 UTC
    How about making a copy of Win32::Word::Writer, re-engineering it into a Win32::Word::Reader and releasing it back to CPAN.


    Free your mind

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://511120]
Approved by gube
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-03-28 12:39 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (67 votes). Check out past polls.