Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 12th, 2007, 10:23 PM   #1
skm376
Newbie
 
Join Date: Feb 2007
Posts: 1
Rep Power: 0 skm376 is on a distinguished road
OOP Perl

I am new to using OO Perl and am having some difficulties gettting started. Basically, I have defined a class called Connection that defines a Connection object. A Connection is a tcp connection, so an instance of the class stores a source IP, source port, destination IP, etc. I have tested the class and as far as I can tell, it is working correctly. However, I want to create an array of Connections to keep track of all the connections in an tcpdump trace file. Perl doesn't complain when I create a new Connection and push it onto an empty array called @connections. However, when I try to reference that object I get an error. Here is some of the relevant code:


my @connections = {};
my $new_connection = eval { Connection->new(); } or die (@_);
$new_connection->sourceIP($sIP);
$new_connection->destinationIP($dIP);
push(@connections, $new_connection);

# loop through connections array
my $index;
for($index=0; $index<$#connections; $index++) {
  if ($connections[$index]->sourceIP() eq $sIP) {
    # do some stuff
  }

Like I said, there are no compilation errors, and there are no errors in creating the $new_connection object or pushing it onto the empty array. The run-time error I am getting comes from the line:

if ($connections[$index]->sourceIP() eq $sIP )

The error I am getting is :
Can't call method "sourceIP" on unblessed reference at line 69

However, the object is blessed. I have tested just declaring a single object and that seems to be working. It is only when I try to refer to it in an array that I get the problem.

I am not sure if I can even declare an array of a user-defined class. Is this possible, and if not how can I go about storing large amounts of instances of my class?

Thanks,
skm376
skm376 is offline   Reply With Quote
Old Nov 1st, 2007, 8:24 PM   #2
fahlyn
Newbie
 
Join Date: Nov 2007
Posts: 15
Rep Power: 0 fahlyn is on a distinguished road
Re: OOP Perl

I noticed that its been awhile since you posted this....did you ever get your problem resolved?
fahlyn is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Perl ReggaetonKing Perl 42 Oct 20th, 2006 4:42 PM
Bash or Perl? titaniumdecoy Other Scripting Languages 9 Jan 30th, 2006 4:42 PM
A simple perl script satimis Perl 3 Aug 15th, 2005 9:31 AM
Why do most shared hosting services offer php not perl? Jonnno Perl 5 May 19th, 2005 3:56 PM
Learning and Programming Perl G.I.Josh Perl 2 Mar 23rd, 2005 1:48 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC