SYNOPSIS

  use File::Slurp::Unicode;

  my $text = read_file('filename', encoding => 'utf8');
  my @lines = read_file('filename'); # utf8 is assumed if no encoding.

  write_file('filename', { encoding => 'utf16' }, @lines);

  # same as File::Slurp::write_file (ie. no encoding):
  write_file('filename', { encoding => 'binary' }, @lines);

  use File::Slurp::Unicode qw(slurp);

  my $text = slurp('filename', encoding => 'latin1');

DESCRIPTION

This module wraps File::Slurp and adds character encoding support through the \*(C`encoding\*(C' parameter. It exports the same functions which take all the same parameters as File::Slurp. Please see the File::Slurp documentation for basic usage; only the differences are described from here on out.

\fBread_file\fP

Pass in an argument called \*(C`encoding\*(C' to change the file encoding. If no argument is passed in, \s-1UTF-8\s0 encoding is assumed.

The special encoding 'binary' is interpreted to mean that there should be no decoding done to the data after reading it. This is pretty much the same as calling \*(C`File::Slurp::read_file()\*(C' directly. This option is here only to make code which needs to read both binary and text files look uniform.

\fBwrite_file\fP

Pass in an argument called \*(C`encoding\*(C' to change the file encoding. If no argument is passed in and no wide characters are present in the output data, then no conversion will be done. If there are wide characters in the output data then \s-1UTF-8\s0 encoding is assumed.

The special encoding 'binary' is interpreted to mean that there should be no encoding done to the data before writing. If you pass a wide string (a string with Perl's internal 'utf8 bit' set) to \*(C`write_file\*(C' and set the encoding to 'binary' it will die with an appropriate message. This is pretty much the same as calling \*(C`File::Slurp::write_file()\*(C' directly. This option is here only to make code which needs write both binary and text files look uniform.

RELATED TO File::Slurp::Unicode…

File::Slurp

BUGS

None known. Contact author or file a bug report on \s-1CPAN\s0 if you find any.

COPYRIGHT

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

Copyright (C) 2010 David Caldwell

AUTHOR

David Caldwell <[email protected]>

<http://porkrind.org/>

PROJECT HOME

<http://github.com/caldwell/File-Slurp-Unicode>