in reply to changing record separator to all my perl programs

What OS are you using? This sounds fishy.

My guess is that you're looking at a text file that was transferred in binary mode between two different operating systems. Macs, Unix/Linux, and Windows machines each have their own "end of line" sequence. If you transfer a text file blindly between these OS's, you end up with a minor problem. Unix has utilities to deal with this after the fact, in case a file's line-endings got messed up somehow.: dos2unix and unix2dos.

So, if your Perl script is having difficulty recognizing line endings, you've probably simply got your line endings mismatched.

One solution is to simply check the line endings of your text files to ensure they're correct, and if not, fix them. It's trivial to write a Perl script to do this for you. Another solution would be to build line-end fixing logic into your scripts, but that seems like too much fiddling for such a common and simple problem.

And of course, from now on, be sure to transfer your text files in text mode via software smart enough to fix the line endings for you in the first place.


Dave

  • Comment on Re: changing record separator to all my perl programs

Replies are listed 'Best First'.
Re^2: changing record separator to all my perl programs
by greatshots (Pilgrim) on Oct 13, 2006 at 08:23 UTC

    I am using hp unix. I am running the program in ksh. both the perl program and all input files residing in same OS.

      all input files residing in same OS

      But what generates these input files? Are you sure that they have the correct Unix line endings in them? Have you looked at them using a utility like od?

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg