Created
February 1, 2019 00:35
-
-
Save jflopezfernandez/647ba7bc86e4817f88a3c23a9c78afc7 to your computer and use it in GitHub Desktop.
Read configuration file in Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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