Posted: Tue, Apr 26 07:27 AM (PDT)
The easy solution for Perl to have any configuration parameters of your application in a file
#!/usr/bin/perl
my %config = load_config("/etc/perl_application.conf");
sub load_config {
my $conf_name = $_[0];
my %config = {};
open(CFG, "<".$conf_name);
while() {
chomp;
my ($var, $val) = split(/\s*\=\s*/);
if ($val eq 'true') { $config{$var} = true; }
if ($val eq 'false') { $config{$var} = false; }
if (($var=~/^\#/is) || ($var eq '')) { } else { $config{$var} = $val; }
}
close(CFG);
# Dump config file
foreach my $key (keys %config) {
if ($key=~/^HASH/is) { } else {
print $key.": ".$config{$key}."\n";
}
}
return %config;
}
perl_application.conf
# MongoDB Settings
mongo_host = 127.0.0.1
mongo_port = 27017
mongo_database = atlas365
mongo_auth = false
# MySQL Settings
mysql_host = 127.0.0.1
mysql_port = 3306
mysql_database = atlas365
mysql_username = mysqlusr
mysql_password = mysqlpswd
Tags:
Posted: Mon, Apr 18 10:33 AM (PDT)
Perl Net::DNS library can be used to write powerful web or OS system applications involving DNS lookups and queries. In this tutorial I will show you how to write a DNS diagnostic application involving DNS and resolver.
Tags: