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

I downloaded the latest CVS version of Crystal Space and want to try to figure out some things about it ... unfortunately on my Windows machine, the files don't look too pretty.

I get little rectangular looking objects (they can't be displayed here) where line breaks should be. I figured this may have something to do with the (wierd?) way Microsoft handles end-of-lines, and want to make a perl script to solve it (or get it the correct way in the first place).

How would I recursively go through the directories opening only files that would have such text (.h,.c,.cpp, etc.) and change them to the correct format? (some files don't have extensions, so I expect I'd have to hard-code those in)

Replies are listed 'Best First'.
Re: file cleaning up
by Aristotle (Chancellor) on Aug 18, 2002 at 00:53 UTC
    File::Find is your friend.
    use File::Find; find(\&process, qw(C:/foo C:/bar)); sub process { return unless /\.(?:h|c|cpp)\z/ and -f $File::Find::name; open FH, "+<", $File::Find::name; s/$some_character// while <FH>; close FH; }
    ____________
    Makeshifts last the longest.
Re: file cleaning up
by JayBonci (Curate) on Aug 18, 2002 at 02:40 UTC
    To change the file format above, you'll want to open the files, and simply run
    $textorline =~ s/([^\r])\n/$1\r\n/g;
    That will change the blocky newlines into Windows CRLF lines, making it much more readable in a program such as Notepad. Keep in mind that other viewers for Windows, such as the standard wordpad.exe will properly translate the files.

        --jb