How can I handle configuration files in Perl?

I am reorganizing an old script that performs some operations on different sites. It should use a configuration file, which is now a text file with manual analysis with the following format:

label:domain:username:password:path 

Of course, the number of rows is potentially unlimited.

I know that there are several modules that deal with configuration files. Which one is best for this situation?

+4
source share
1 answer

If you are looking to change the format, check out the recommendations here:

How do you manage configuration files in Perl?

If you are looking for parsing an existing format, this format looks more like a comma-delimited file than a configuration file, so I would say go to Text :: CSV (it allows you to select the delimiter character in the constructor, so you can separate the colon, not separated by commas) or for very large Text :: CSV_XS files.

 use Text::CSV; # Example adapted from POD my @rows; my $csv = Text::CSV->new ( { sep_char => ":" } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", "test.conf" or die "test.conf: $!"; while ( my $row = $csv->getline( $fh ) ) { push @rows, $row; # $row is arrayref containing your fields } $csv->eof or $csv->error_diag(); close $fh; 
+5
source

All Articles