Hope this helps :-)

Basically the %hash variable contains another hash, and with spaces in
keys you cannot use them with "<>"


use Config;
use Config::INI;

my Str $IniFile = slurp "config.ini";
my %hash = Config::INI::parse($IniFile);

dd %hash;
print "\n";

for %hash.kv -> $section_name, %section_value  {

    put "on $section_name we have: ";
    for %section_value.kv -> $key, $value {
        put "$key -> $value";
    }

}

print "\n";

put %hash{'Backup paramters'}<target>;


ToddAndMargo via perl6-users <perl6-us...@perl.org> escreveu no dia
sábado, 30/05/2020 à(s) 00:02:
>
> Hi All,
>
> I an not figure out how to read the hash.
>
>
> ~~~~~~~~~~~ ini.test.pl6.ini ~~~~~~~~~~~~~
> # Raku: Confug::INI test INI
> # edit at your own risk
>
> [Backup paramters]
> target=B:\myDocsBackp\backup1
> partition=BACKUP
>
> [eMail]
> smtp=smtp.bozo.com
> address=b...@theclown.com
> port=587
> ~~~~~~~~~~~ /ini.test.pl6.ini ~~~~~~~~~~~~~
>
>
> ~~~~~~~~~~~ ini.test.pl6 ~~~~~~~~~~~~~
> #! /usr/bin/env raku
>
> #`{
>      # zef install Config
>      # zef install Config::INI
>
>
>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
>      line 45 starts documtation
>
>      use Config::INI;
>      my %hash = Config::INI::parse_file('config.ini');
>      #or
>      %hash = Config::INI::parse($file_contents);
>      say %hash<_><root_property_key>;
>      say %hash<section><in_section_key>;
>
>      This module provides 2 functions: parse() and parse_file(), both taking
>      one C<Str> argument, where parse_file is just parse(slurp $file).
>      Both return a hash which keys are either toplevel keys or a section
>      names. For example, the following config file:
>
>      foo=bar
>      [section]
>      another=thing
>
>      would result in the following hash:
> }
> #   { '_' => { foo => "bar" }, section => { another => "thing" } }
>
>
> use Config;
> use Config::INI;
>
> my Str $IniFile = slurp "ini.test.pl6.ini";
> my %hash = Config::INI::parse($IniFile);
>
> dd %hash;
> print "\n";
>
> for %hash.kv -> $key, $value  { print "   hash<$key> = [$value]\n\n"; }
> print "\n";
> ~~~~~~~~~~~ /ini.test.pl6 ~~~~~~~~~~~~~
>
> ~~~~~~~~~~~~~ run the test ~~~~~~~~~~~~
> $ ini.test.pl6
>
> Hash %hash = {"Backup paramters" => ${:partition("BACKUP"),
> :target("B:\\myDocsBackp\\backup1")},
> :eMail(${:address("bozo\@theclown.com"), :port("587"),
> :smtp("smtp.bozo.com")})}
>
>     hash<Backup paramters> = [partition BACKUP
> target  B:\myDocsBackp\backup1]
>
>     hash<eMail> = [address      b...@theclown.com
> port    587
> smtp    smtp.bozo.com]
> ~~~~~~~~~~~~~ /run the test ~~~~~~~~~~~~
>
>
> How do I read the hash so I get section
> `[eMail]` `smtp`?  (Or any of the other values
> as well.)
>
>
> Many thanks,
> -T

Reply via email to