Perl configuration files

There are many ways to read data/configuration from file in perl.
Such like, parsing text file which is coma/tab delimited, reading from json file or other format using extra json package.

The following should be the simplest way, if you control the input.
#my.conf
return
{
    start_time => '10 pm'
};

Read configuration file which is perl format. Function 'do' will execute the input as a perl file and return the result.
#!/usr/bin/perl -w
use Data::Dumper;

my $hashref = do 'my.conf';
print Dumper($hashref);

Output:
$VAR1 = {
          'start_time' => '10 pm'
        };

No comments:

Post a Comment