The stupid question is the question not asked | |
PerlMonks |
Re^5: Return a valueby 1nickt (Canon) |
on Jul 06, 2015 at 11:13 UTC ( [id://1133342]=note: print w/replies, xml ) | Need Help?? |
You need to capture the return value! Your sub returns a hashref, so you have to capture the return value into a hashref in your main program. Right now you are not assigning the return value to anything. (Looks like you tried a hash and it didn't work because you were getting a hashref.) If you want to use it as a hash in your program, you must dereference it. (Although I would keep it as a hashref.)
But really, I would find and use a CPAN module for common tasks like this. It is a good practise exercise to write your own sub, but it is also "reinventing the wheel." You should put your limited time and efforts into writing your application code; that which is NOT available on CPAN! Here's what you could do instead, using your same .ini file. No need to write or maintain a separate sub for getting your config information:
I urge you to try this, not just look at it. Install Config::Tiny, copy this script to your test folder, and try it!
Remember: Ne dederis in spiritu molere illegitimi!
In Section
Seekers of Perl Wisdom
|
|