in reply to Hash reference undefined somewhere?
update: I'm using 'use strict; use warnings' now, but now the issue is that the ProcessFile subroutine, when %do_for is defined, it goes through and executes each subroutine. I'd expected it to only run later, when I run $do_for{$what_to_do} explicitly. I'd like to use this instead of a cascading if... thoughts?Calling a subroutine is calling a subroutine. Why would you expect it to somehow magically create a subroutine reference and not execute the code?? It's just in list context -- the '=>' is just a special form of the comma that usually lets you get way with using barewords to the left of it. For anything to the right of it there is really no difference between '=>' and ','.
It's similar to what you do later on:
print "here GetHosts - " . Dumper($ref_data) . "\n";
Which can be rewritten with commas like below (which in theory performs better because concatenation can be expensive, especially when it's unnecessary):
print "here GetHosts - ", Dumper($ref_data), "\n";
Now, you would expect Dumper to actually be called here vs. creating a reference to it, right? Right?? So what you need to do is create subroutine references ('\&') like in the following (untested; based on some really old code):
my %do_for = ( get_hosts => \&GetHosts, get_new_fw_rules => \&GetNewFWRules, ); #... $do_for({$what_to_do}->( $_, \%data );
Elda Taluta; Sarks Sark; Ark Arks
|
---|