commit: a11addf203d3ee4d043f5dc1aca9451ec98166a9
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Aug 19 15:42:53 2025 +0000
Commit: Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Tue Aug 19 15:42:53 2025 +0000
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=a11addf2
mkconfig: use read_lines() to read the SUPPORTED file
Use the read_lines() method of File::Slurper to consume the SUPPORTED
file. Doing so might use a little more memory than does reading line by
line. However, it confers the advantage of decoding the input as UTF-8
and throwing an exception if malformed.
See-also: 945525e71206428f87f94b839fe4ce36b9d85e1e
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
mkconfig | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mkconfig b/mkconfig
index c455a54..b52beb5 100755
--- a/mkconfig
+++ b/mkconfig
@@ -13,15 +13,15 @@ use v5.36;
use File::Spec::Functions qw(catdir catfile);
use Unicode::Normalize qw(NFKD);
-use File::Slurper qw(read_text);
+use File::Slurper qw(read_lines read_text);
{
# The first argument shall be treated as a prefix, if any.
my $prefix = @ARGV ? $ARGV[0] : '';
- # Open the file containing the supported locale/charmap combinations.
+ # Read the file containing the supported locale/charmap combinations.
my $path = catfile($prefix, '/usr/share/i18n', 'SUPPORTED');
- open my $fh, '<', $path or die "Can't open '$path': $!";
+ my @lines = read_lines($path);
# Gather the language and territory attributes of the locale templates.
my $attr_by = map_locale_attributes($prefix);
@@ -29,7 +29,7 @@ use File::Slurper qw(read_text);
# Use column(1) to write out a nicely columnated list.
my $pipe = open_column("\037");
- while (my $line = readline $fh) {
+ for my $line (@lines) {
my ($read_locale, $charmap) = split ' ', $line;
# The names of the templates don't incorporate a codeset part.
@@ -51,7 +51,6 @@ use File::Slurper qw(read_text);
printf {$pipe} "# %s\037%s\037# %s\n", $read_locale,
$charmap, $comment;
}
}
- close $fh;
close $pipe or exit 1;
}