bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hash reference undefined somewhere?
by wind (Priest) on Mar 09, 2011 at 22:03 UTC | |
by bowei_99 (Friar) on Mar 09, 2011 at 23:23 UTC | |
Re: Hash reference undefined somewhere?
by GrandFather (Saint) on Mar 09, 2011 at 23:20 UTC | |
by bowei_99 (Friar) on Mar 09, 2011 at 23:49 UTC | |
by GrandFather (Saint) on Mar 09, 2011 at 23:59 UTC | |
by bowei_99 (Friar) on Mar 09, 2011 at 23:46 UTC | |
Re: Hash reference undefined somewhere?
by Argel (Prior) on Mar 10, 2011 at 22:30 UTC |