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;

-- Ken

p in

In reply to Re^3: Using config::any by kcott
in thread Using config::any by ItsyBitsy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.