#!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Config::Tiny; sub showusage { print <... Options: -h, --help print this help message. --config-file= use as the config file. --config-section= use
instead of 'rtpengine'. --fallback-table= use as fallback table instead of 0. HELP } my %options = ( 'help' => sub { showusage(); exit 0 }, 'config-file' => '/etc/rtpengine/rtpengine.conf', 'config-section' => 'rtpengine', 'fallback-table' => -1, ); Getopt::Long::Configure('require_order'); my $optret = GetOptions(\%options, 'help|h', 'config-file=s', 'config-section=s', 'fallback-table=i', ); if (!$optret) { showusage(); exit 1; } my $cfg = Config::Tiny->read($options{'config-file'}); if (not defined $cfg) { die "error: " . Config::Tiny->errstr . "\n"; } my $cfg_section = $options{'config-section'}; my $table = $cfg->{$cfg_section}{table} // $options{'fallback-table'}; print "$table\n"; 1;