in reply to Hash reference undefined somewhere?

Always use strictures (use strict; use warnings;)!

GetHosts takes a reference parameter which you assign to a local variable $ref_data. Later in the same function you redefine the variable twice (inside the if)! That is three different variables using the same name in the same function. That can not be right. With strictures on you would get:

"my" variable $ref_data masks earlier declaration in same scope at ... Use of uninitialized value $new_ip in concatenation (.) or string at . +..

which happens to tell you exactly where the problems are. Did I mention "Always use strictures (use strict; use warnings;)" already? You really, really should.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Hash reference undefined somewhere?
by bowei_99 (Friar) on Mar 09, 2011 at 23:49 UTC
    Actually, I got it - I changed it to this
    if ($old_ip) { print "here old ip $old_ip, hostname $hostname, new ip $new_ip + \n"; $ref_data->{$old_ip}{"hostname"} = $hostname; $ref_data->{$old_ip}{"new_ip"} = $new_ip; }
    which works now. I knew it was something trivial. :)

    -- Burvil

      But are you using strictures now?

      True laziness is hard work
Re^2: Hash reference undefined somewhere?
by bowei_99 (Friar) on Mar 09, 2011 at 23:46 UTC
    Great! I'm just not sure how to get around this.... I do have the following at the top level, in main:

    my $ref_data = ProcessFile($fh, "get_hosts");
    I also have $ref_data defined in the GetNewFWRules subroutine in the same way I have for GetHosts. But aren't all of those declarations in different scopes, i.e. main vs. a subroutine?

    Either way, I changed the declaration in main to $ref_data2, and I still get the same thing. There are no other declarations of $ref_data.

    -- Burvil