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.)

my $return_value = Read_INI_files_get_initialData_PP_DB(); my %Section1 = %$return_value; print "$Section1{SQL1}\n";

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:

#!/usr/bin/env perl use strict; use warnings; use Config::Tiny; my $ini_file = '/home/testtool/config/InitialData.ini'; my $ini = Config::Tiny->read($ini_file) or die; my $Section1 = $ini->{'Section1'}; my $SQL1 = $Section1->{'SQL1'}; # or ... my $SQL2 = $ini->{'Section1'}->{'SQL2'}; print "SQL1: $SQL1\n"; print "SQL2: $SQL2\n";

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 reply to Re^5: Return a value by 1nickt
in thread Return a value by bhushanQA

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.