in reply to Strange File read problem

I'm betting you have carriage returns and not newlines at the end of each line. Try this:

open FILE, "Sample.java" or die "Cannot open file: $!\n"; while (<FILE>) { s/\r/\\r/g; print "$_\n"; } close FILE;

Replies are listed 'Best First'.
Re: Re: Strange File read problem
by abhishes (Friar) on Apr 09, 2003 at 19:51 UTC
    Yes !!! That did the trick!!!
    I changed the code to
    open FILE, "c:\sample.java"; while(<FILE>) { s/\r/\n/g; print "$_\n"; } close FILE;

    And it printed the file correctly.

    thanks for your help. I was so puzzled. How did you figure it out?

    regards,
    Abhishek.