Your code worked for the above .ini file when i added use feature "say".
It sounds like you've got a handle on that. feature shows other ways to achieve this: you may have read that already.
However for my password.ini file it still prints the password as a reference. (only the last line though). Any idea why this is happening?
In this type of situation, you should show the output you received. The page "How do I post a question effectively?" explains this along with other useful advice: I strongly recommend you read it. Not doing so is likely to result in responses like "Sorry, I don't have the Mental::Telepathy module installed on my system.". :-)
I'll guess your output looked something like:
Full $cfg structure:
$VAR1 = [
{
'C:\wamp\www\password.ini' => {
'password' => {
'password' => '
+mypass'
}
}
}
];
Password: HASH(0x7f9a03843da8)
Side issue: with a double-quoted string you need to escape all the special characters, with a single-quoted string you don't. Compare "C:\\wamp\\www\\password.ini" with 'C:\wamp\www\password.ini'. Take a look at Quote-Like Operators in perlop for more details.
Using a section header (e.g. [password]) adds an additional level to your data structure. Using this ini file:
[password]
password=mypass
[other_section]
other_key=other_value
I get this output:
Full $cfg structure:
$VAR1 = [
{
'./pm_config_any.ini' => {
'other_section' => {
'other_key
+' => 'other_value'
},
'password' => {
'password' => '
+mypass'
}
}
}
];
So, to get the value you're after you'll need:
say q{Password: }, $cfg->[0]{$pw_ini_file}{password}{password};
Also how would i store this into a string.
That's a basic assignment - you don't need to do anything special:
my $ini_password = $cfg->[0]{$pw_ini_file}{password}{password};
say $ini_password;
p in |