cdeloos has asked for the wisdom of the Perl Monks concerning the following question:
The problem is in the output of $int{$key}{ip}-print_cidr(). When I call it from within the block that created the object it works fine, but when I do so from another block, later on in the program I get an error message: Can't call method "print_cidr" without a package or object reference output:#!/usr/bin/perl use strict; use warnings; use Switch; use MyIP; my %int; my $cur_int=""; open (CONF, "ipplan.cfg") or die "file does not exist\n"; while (<CONF>) { switch ($_) { case /^interface / { (undef, $cur_int, undef) = split / /; $int{$cur_int}{ip}=""; } case /^ ip address [\d\.]+ [\d\.]+$/ { my (undef, undef, $ip, $mask, undef) = split / /; $int{$cur_int}{ip}=new MyIP ($ip, $mask) or die "incorrect IP addr +ess: $ip $mask\n"; print "$cur_int: $ip $mask = ", $int{$cur_int}{ip}->print_cidr(), +"\n"; } } close CONF; foreach my $key (keys %int) { print "int $key \n"; print " ip address ",$int{$key}{ip}->print_cidr(), "\n"; }
but, when removing the call to print_cidr and just printing the object, i.e.:Loopback0: 172.25.10.10 255.255.255.255 = 172.25.10.10/32 int Loopback0 Can't call method "print_cidr" without a package or object reference a +t ./conf.pl line 83.
a reference to a MyIP object does appear...foreach my $key (keys %int) { print "int $key \n"; print " ip address ",$int{$key}{ip}, "\n"; }
so my question is what i am doing wrong here... and of course what I can do to fix this! Your help is much appreciated.Loopback0: 172.25.10.10 255.255.255.255 = 172.25.10.10/32 int Loopback0 ip address MyIP=HASH(0x84eeef4)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: object scope problem?
by kyle (Abbot) on Feb 12, 2008 at 17:26 UTC | |
|
Re: object scope problem?
by chromatic (Archbishop) on Feb 12, 2008 at 19:06 UTC | |
|
Re: object scope problem?
by FunkyMonk (Bishop) on Feb 12, 2008 at 23:04 UTC |