The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

EOL - This module aids in the conversion of text file newline characters within the context of other perl code; includes command line executable.

VERSION

This document describes EOL version 0.0.2

SYNOPSIS

    ### EOL NEW FILE (makes Unix)
    use EOL;
    my $in  = "original.txt";
    my $out = "converted.txt";
    EOL::eol_new_file(
                      in  => $in,
                      out => $out,
                      eol => "LF"
                     );

    ### EOL SAME FILE (makes older Mac)
    use EOL;
    my ($in) = $ARGV[0] = "original.txt"; # Must prime @ARGV!
    EOL::eol_same_file(
                       in     => $in,
                       eol    => "CR",
                       backup => ".bak"
                      );

    ### EOL RETURN ARRAY (makes MS-DOS)
    use EOL;
    my $in = "original.txt";
    my $aref = EOL::eol_return_array(
                                     in     => $in,
                                     eol    => "CRLF",
                                    );

Also, see the t/EOL.t test case for examples of implementation. A quick assessment of the converted file can be done by using cat.

 cat -ve <converted file>

DESCRIPTION

There are several easy, quick command line methods for converting text file line endings, including the venerable:

 perl -i.bak -pe 's/\r\n/\n/' <file>

This module provides routines for newline conversion that may be used in-line within large perl applications. A command line executable which utilizes this module is also included; see:

 perldoc eol

INTERFACE

The following routines are supported:

eol_new_file

eol_new_file: A routine to convert line endings and write to a new file. Original file is untouched. This routine takes two incoming arguments which correspond to input and output file names. By default, all newlines will be converted to standard Unix-style line feeds (LF or octal \012). A user may change the end-of-file tag manually by supplying the "eol" argument. Acceptable eol tags are: CR; CRLF; LF.

 eol_new_file(
              in  => $in,
              out => $out,
              eol => 'LF',
             );

eol_same_file

eol_same_file: A routine to convert line endings and write to the original file (i.e., clobbers the file you send it). The developer may specify that the original be backed-up a *single* time. This routine takes an incoming argument which corresponds to an input file name. By default, all newlines will be converted to standard Unix-style line feeds (LF or octal \012). A user may change the end-of-file tag manually by supplying the "eol" argument. Acceptable eol tags are: CR; CRLF; LF. As already mentioned, this routine will clobber the in-file. Sending the "backup" argument with a file suffix will produce a one-time backup of the original file. THIS ROUTINE WILL EDIT THE INCOMING FILE IN-PLACE. USE AT OWN RISK.

 my ($in) = $ARGV[0] = "original.txt"; # Must prime @ARGV.
 eol_same_file(
               in     => $in,
               eol    => "CR",
               backup => ".bak"
              );

eol_return_array

eol_return_array: A routine to convert line endings and return an array reference of all of the converted line. This routine takes one incoming argument which corresponds to an input file name. By default, all newlines will be converted to standard Unix-style line feeds (LF or octal \012). A user may change the end-of-file tag manually by supplying the "eol" argument. Acceptable eol tags are: CR; CRLF; LF. An array reference to the converted file lines will be returned. Obviously, for larger files, this may be a considerable drain on memory. NOTE: End of line characters are returned as their own fields in the array--that is, they are not tacked on to the proceeding line.

 my $aref = eol_return_array(
                             in  => $in,
                             eol => 'CRLF',
                            );

DIAGNOSTICS

A user may encounter error messages associated with this module if required method arguments are malformed or missing.

[An argument was passed that is not legal. See INTERFACE for appropriate arguments per subroutine.]

EOL reports: not a text file

[A path to a non-plaintext file was passed as input.]

EOL reports: cannot open file

[There was an error trying to read/or write a file.]

[An illegal option was passed to the "eol" option. Legal options are CR; CRLF; LF]

CONFIGURATION AND ENVIRONMENT

EOL requires no configuration files or environment variables.

DEPENDENCIES

This module calls a few others: strict; warnings; Carp; version.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-eol@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Todd Wylie

<perldev@monkeybytes.org>

http://www.monkeybytes.org

LICENSE AND COPYRIGHT

Copyright (c) 2005, Todd Wylie <perldev@monkeybytes.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

NOTE

This software was written using the latest version of GNU Emacs, the extensible, real-time text editor. Please see http://www.gnu.org/software/emacs for more information and download sources.