aboutsummaryrefslogtreecommitdiffstats
path: root/Perl
diff options
context:
space:
mode:
authorBas Zoetekouw <bas>2008-12-19 18:24:28 +0000
committerBas Zoetekouw <bas>2008-12-19 18:24:28 +0000
commit392af4a1ed94531f875663d79ddaecde181665b5 (patch)
tree038e49d6a53dc1c6d53a4f59070598a2521852d9 /Perl
parent1aa0368035cdb08e5284f51164cf82a03f8cba09 (diff)
Add optional argument to read_file() that sepcifies the encoding the file is
in. CVS version numbers Perl/Local/Util.pm: 1.2 -> 1.3
Diffstat (limited to 'Perl')
-rw-r--r--Perl/Local/Util.pm11
1 files changed, 10 insertions, 1 deletions
diff --git a/Perl/Local/Util.pm b/Perl/Local/Util.pm
index 137764b6b0d..142b513f5dc 100644
--- a/Perl/Local/Util.pm
+++ b/Perl/Local/Util.pm
@@ -67,6 +67,8 @@ sub uniq (@)
Slurps an entire file and returns the contents of the file as a scalar, or
undef if an error occured (actual error will be in $!).
+The optional second argument can be used to specify the charset the file is in.
+
This function is mean as a light-weight replacement for File::Slurp.
=cut
@@ -74,12 +76,19 @@ sub read_file
{
my $filename = shift
or croak("Local::Util::read_file: no file specified");
+ my $encoding = shift;
+
+ my $input = '<';
+ if ( $encoding )
+ {
+ $input .= ":encoding($encoding)";
+ }
# slurp mode
local $/ = undef;
# read the file
- open( my $fd, '<', $filename ) or return;
+ open( my $fd, $input, $filename ) or return;
my $text = <$fd>;
close( $fd );

© 2014-2024 Faster IT GmbH | imprint | privacy policy