Skip to content

Instantly share code, notes, and snippets.

@jflopezfernandez
Created February 1, 2019 00:35
Show Gist options
  • Save jflopezfernandez/647ba7bc86e4817f88a3c23a9c78afc7 to your computer and use it in GitHub Desktop.
Save jflopezfernandez/647ba7bc86e4817f88a3c23a9c78afc7 to your computer and use it in GitHub Desktop.
Read configuration file in Perl
#/usr/bin/perl
use strict;
use warnings;
my $FileName = "Config.ini";
my %UserConfiguration;
open(CONFIG, "<:encoding(UTF-8)", $FileName) or die "Failed to open configuration: $FileName\n";
while (<CONFIG>) {
chomp;
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
my ($Var, $Val) = split(/\s*=\s*/, $_, 2);
$UserConfiguration{$Var} = $Val;
}
while (my ($k, $v) = each %UserConfiguration) {
print "$k: $v\n";
}
my $Status = system("notepad", $FileName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment