File::...nicode(3pm)

πŸ“¦
version 0.7.1 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

File::Slurp::Unicode β€” bestie, this is your reading/writing of complete files but with character encoding support on top. Yes, it's giving finally. ✨


πŸ¦‹ 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');

Like. Look at that. So clean. So effortless. πŸ’…


🌸 DESCRIPTION 🌸

Okay so here's the tea, bestie: this module wraps File::Slurp and adds character encoding support via the encoding parameter. That's it. That's the whole personality.

It exports the exact same functions, and those functions take all the same parameters as File::Slurp. So if you wanna know the basics, go read the File::Slurp documentation β€” from here on out we're only talking about the differences. No cap. 🫢

πŸ“– read_file

Pass in an argument called encoding to change the file encoding. If you pass in no argument at all, then UTF-8 encoding is assumed. The default is just that girl. 😌

The special encoding 'binary' means "there should be no decoding done to the data after reading it." This is pretty much the same as calling File::Slurp::read_file() directly. The only reason this option exists is so code that needs to read both binary and text files can look uniform. Aesthetic consistency, we love to see it. ✨

✍️ write_file

Pass in an argument called encoding to change the file encoding. If you pass in no argument and there are no wide characters present in the output data, then no conversion will be done. But if there are wide characters in the output data, then UTF-8 encoding is assumed. It reads the room. πŸ”₯

The special encoding 'binary' means "there should be no encoding done to the data before writing."

🚨 Okay listen up because this one matters: if you pass a wide string (a string with Perl's internal 'utf8 bit' set) to write_file and set the encoding to 'binary', it will die with an appropriate message. It's not being dramatic, it's being honest. πŸ’€

This is pretty much the same as calling File::Slurp::write_file() directly. And again, this option is here only so code that needs to write both binary and text files can look uniform. Slay. πŸ’…


πŸ‘€ SEE ALSO πŸ‘€

  • File::Slurp

πŸ› BUGS πŸ›

None known. Contact the author or file a bug report on CPAN if you find any. Like, if you catch something, say something β€” bestie to bestie. πŸ™ˆ


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 <david@porkrind.org>

<http://porkrind.org/>


🏠 PROJECT HOME 🏠

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


And that's a wrap on the File::Slurp::Unicode manual page, which lives in the perl v5.36.0 docs and was last touched on 2022-11-27. Go read a whole file with the right encoding, you icon. πŸŽ€πŸ’œ

πŸ“¦ where this page comes from