CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
help for the perl oop

 



chefchanyu
New User

Jul 12, 2012, 9:10 PM

Post #1 of 2 (922 views)
help for the perl oop Can't Post

Hi:

did anyone know why I got this error and how to fix it?


-sh-4.1$ perl mgw01.pl
Can't locate object method "dir" via package "mgw" at mgw01.pl line 19.


mgw01.pl

Code
#!/usr/bin/perl -I/var/www/cacti_script/BROKER/script1 
use strict;
use warnings;
use Time::Local;
use mgw;

main(@ARGV);

sub main
{
my $o = mgw->new;
$o->name("chef");
my $name = $o->name;
#message($name);

my $o2 = mgw-> new;
$o2->cdr_time("01");
#$o2->dir;
message($o->dir);

}

sub message
{
my $m = shift or return;
print("$m\n");
}


mgw.pm

Code
package mgw; 

use strict;
use warnings;
use IO::File;

our $VERSION = "1.0";
our $log_path = "/var/www/cacti_script/BROKER/script1/log";
our $cdr_path = "";

our %REGEXP =(
CDR_TIME => qr/(\d\d).log.((\d\d\d\d\d\d)\d+)/,
);

sub new {
my $class = shift;
my $self = {};
bless($self, $class);
return $self;

}

sub name
{
my ($self, $name) = @_;
$self->{name} = $name if defined $name;
return $self->{name};
}

sub cdr_time
{
my ($self, $relay) = @_;
my $dir = "";
my $cdrtime = "";

open(FILE, "$log_path/$relay/cdr");
while(my $line = <FILE>)
{
my $regexp = $REGEXP{"CDR_TIME"};
if($line =~ /$regexp/)
{
$dir = $2;
$cdrtime = $3;
}
}
close FILE;
$self->{dir} = $dir if defined $dir;
$self->{cdrtime} = $cdrtime if defined $cdrtime;

return $self->{dir};
}



FishMonger
Veteran / Moderator

Jul 13, 2012, 6:13 AM

Post #2 of 2 (890 views)
Re: [chefchanyu] help for the perl oop [In reply to] Can't Post

Your mgw module doesn't define a dir method/subroutine.


(This post was edited by FishMonger on Jul 13, 2012, 6:15 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives