theleftsock has asked for the wisdom of the Perl Monks concerning the following question:
I am probably reinventing the wheel here but I am attempting to correct a problem i glossed over earlier. I am basically making a call to a sub in another file that I have included using require. When i run it I get the error shown below.
Basically $request_hash is a hash of headers for use with mechanize and sometimes the request requires special handling (date updated and appended, particular cookie added, servers changed, etc.) so it needs to call a function in a another file. The function name is added to the headers as Logic: function_name. This is done manually and the function is added to the request_logic.pl. I am trying to figure out what I am doing wrong. I have used no strict "refs" here, the code works fine that way, and that is wrong. The code works great though, i just want the correct syntax. Any input, ideas, or help would be appreciated.
As a note nnnnn exists as a test function in request_logic.pl. I did not post the whole thing because its about 700 lines now. subs::dbg is the logging function i use.
thanks.
p.s. this is my first posted question, so please forgive me for any formatting mistakes in it. but perlmonks has been an awesome resource. thanks again.
This is the error.if ($request_hash{Logic}) { no strict "refs"; subs::dbg($log_file, 0, "<$script_file> This is the Logic: $requ +est_hash{Logic} \n\n"); $function_name = "request_logic::".$request_hash{Logic}; + eval{$returned_hash_ref = &$function_name($request_hash_ref, $lo +g_file)}; #should call any set function name if ($@) { subs::dbg($log_file, 0, "<$script_file> Error from eval: $@"); #i +f there is an eval error } else { subs::dbg($log_file, 0, "<$script_file> Hash returned from +moodification from function $function_name"); subs::dbg($log_file, 0, Dumper $returned_hash_ref); } delete($request_hash{Logic}); #delete the ha +sh value with the logic in it }
201017 05:28 - <test_check.script> Error from eval: Can't use string ( +"request_l ogic::nnnnn") as a subroutine ref while "strict refs" in use at web_ac +torv.0755. pl line 282, <ACT> line 55.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use strict refs unless you can't figure out the syntax
by GrandFather (Saint) on Jan 07, 2010 at 11:36 UTC | |
by AnomalousMonk (Archbishop) on Jan 07, 2010 at 17:01 UTC | |
by theleftsock (Beadle) on Jan 08, 2010 at 05:01 UTC | |
by GrandFather (Saint) on Jan 08, 2010 at 08:28 UTC | |
by GrandFather (Saint) on Jan 08, 2010 at 07:58 UTC | |
|
Re: use strict refs unless you can't figure out the syntax
by JavaFan (Canon) on Jan 07, 2010 at 11:05 UTC | |
|
Re: use strict refs unless you can't figure out the syntax
by BrowserUk (Patriarch) on Jan 08, 2010 at 07:13 UTC |