http://www.perlmonks.org?node_id=1003796


in reply to Get record separator of a file

I tested my four subs (my basic intention).

Unfortunately it seems as there was some confusion about recsep, line seperator and record seperator. Normally Tie::File treats every line of a file as record, except one changes this behaviour. Or vice versa, loading a file under Windows with has "\n" as line separator led to that Tie::File loaded all data into $array[0]. After setting the recsep option to \n everything worked as expected.

From the documentation if Tie::File: recsep What is a 'record'? By default, the meaning is the same as for the <...> operator: It's a string terminated by $/, which is probably "\n". (Minor exception: on DOS and Win32 systems, a 'record' is a string terminated by "\r\n".) You may change the definition of "record" by supplying the recsep option in the tie call: tie @array, 'Tie::File', $file, recsep => 'es';.

The correct question should better have been: "How can i get the line seperator from a file...?".

Thank you for help to all and best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: Get record separator of a file
by davido (Cardinal) on Nov 14, 2012 at 19:36 UTC

    The correct question should better have been: "How can i get the line seperator from a file...?"

    I think a better question would have been, "How can I use Tie::File with text files from diverse platforms?"

    But we eventually got the point, and I'm glad you got it worked out (:crlf layer).


    Dave

      You're right, Dave.

      Karl

      «The Crux of the Biscuit is the Apostrophe»