in reply to Perl Config::Simple with %hash or @array

is it possible to combine Blocks with hashes or arrays?
It is possible to combine blocks with arrays but not with hashes, however it is easy to convert an array to a hash.

For an array you just need to separate the values with a comma:

[requirements] array=bar,baz hash=bar,1,baz,2
You can then process that:
my $ary = $config{'requirements.array'}; my $hary = $config{'requirements.hash'}; # convert array reference to hash my %hash = @$hary; print "ARRAY:\n"; for my $item (@$ary) { print "$item\n"; } print "HASH:\n"; for my $key (keys %hash) { print "$key => $hash{$key}\n"; }
Output:
ARRAY: bar baz HASH: bar => 1 baz => 2

Replies are listed 'Best First'.
Re^2: Perl Config::Simple with %hash or @array
by thanos1983 (Parson) on Apr 30, 2014 at 08:47 UTC

    To: tangent,

    Perfect!!!! It is excactly what I needed. Really nice explanation and easy to understand.

    I was about to update my question, I figure out that it was impossible to use the sign '%' or '@' on the config.ini file because PHP will not be able to understand this symbols.

    Thank you for your time and effort.