I'm having a problem with a hash assignment, and I'm sure it's something trivial, but I'm not seeing it. The indexes and values in the hash are all defined, so I can't see why Perl is complaining.
I have this chunk of code to process different actions:
my %do_for = ( get_hosts => GetHosts($_, \%data), get_new_fw_rules => GetNewFWRules($_, \%data), ); #print "while\n"; if ( ! $do_for{$what_to_do} ) { warn "ERR - what to do $what_to_do"; };
and the GetHosts sub is:
sub GetHosts { my ($line, $ref_data) = @_; my ($hostname, $old_ip, $new_ip) = split /,/, $line; print "here GetHosts - " . Dumper($ref_data) . "\n"; if ($old_ip) { print "here old ip $old_ip, hostname $hostname, new ip $new_ip + \n"; my $ref_data->{$old_ip}{"hostname"} = $hostname; my $ref_data->{$old_ip}{"new_ip"} = $new_ip; } }
and when I run it, I get this:
here GetHosts - $VAR1 = {}; ere old ip a-valid-ip-here, hostname valid-hostname-here, new ip vali +d-ip-here Can't use an undefined value as a HASH reference at ./fw-rule-convert. +pl line 60, <$IN_FH> line 1. Can't use an undefined value as a HASH reference at ./fw-rule-convert. +pl line 65, <$IN_FH> line 1.
But I don't understand - the only undefined value is the hash itself, which I'm trying to add to; I think that should be OK. The values from the split are in fact the correct values in the first line in the input file, and are not null.
Anybody have thoughts as to why I'm getting this error?
-- Burvil
In reply to Hash reference undefined somewhere? by bowei_99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |