in reply to Re: Record separator in variable
in thread Record separator in variable

I contemplated doing the simple substitution but it's pretty specific to this example. Most customers should use either \n or \r\n for record separators but there is always the chance that one will have an ancient mainframe and send a file with something completely different. I'm looking at String::Interpolate right now, hopefully it will be useful.

Replies are listed 'Best First'.
Re^3: Record separator in variable
by stevieb (Canon) on Jun 06, 2019 at 18:20 UTC

    I wrote File::Edit::Portable for purposes such as this. It's quite flexible in reading and writing files with various record separators. It automatically determines the file's record separator, and the record separator of the platform the software is running on.

    Most of the distribution is Object Oriented based, but it has a couple of handy exports for the most basic functionality as well:

    use strict; use warnings; use File::Edit::Portable qw(recsep platform_recsep); $/ = recsep('file.txt'); # set the recsep to that of a file # or $/ = platform_recsep(); # set the recsep to that of the local platfor +m
Re^3: Record separator in variable
by BillKSmith (Monsignor) on Jun 07, 2019 at 03:09 UTC
    Your code must fully support your user documentation for this field and nothing more. Simple substitution may be a good idea. If you allow the full power of perl interpretation, you probably want the module that does that.
    Bill