Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Return a value

by 1nickt (Canon)
on Jul 06, 2015 at 11:13 UTC ( [id://1133342]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Return a value
in thread Return a value

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found