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

Hi there,

I've got a quite obscure problem concerning linewise parsing of files within my huge project.

Isolated problem:

Runnig this example standalone, everything works fine:

I do have almost the same code within a huge project. Running this code on the same file does not show the same behaviour within my project:

What's going wrong? It used to work formerly - I made a couple of changes "far away" fom this code sequence within my project.

What may perl cause to ignore the CarriageReturn during parsing with while <F>? How can I "force" perl to use carriageReturn as line separator?

???Puzzled???
Hoppfrosch

Replies are listed 'Best First'.
Re: Perl ignores CarriageReturn during fileparsing. Why?
by Athanasius (Archbishop) on Jun 13, 2013 at 12:08 UTC

    The input record separator is stored in the special Perl variable $/. It is newline (i.e., \n, not “carriage return”, which is \r) by default.

    Have your “far away” changes altered the value of $/?

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      You are my god for today - Wrong value within $/ (INPUT_RECORD_SEPARATOR) was the culprit; resetting it to '\n' solves my problem.
      I assumed there has to be a special variable for this - but couldn't find it ...
      Any change I made must have altered the value of $/ - have to find out which.
        Normally the input record separator should only be changed in the scope for which you need to change it
        # code "borrowed" from node 1952 :-) { local $/ = undef; open FILE, "myfile" or die "Couldn't open file: $!"; $string = <FILE>; close FILE; } # $/ reverts back to default here...
        If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)