![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2007
Posts: 1
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2007
Posts: 15
Rep Power: 0
![]() |
Re: OOP Perl
I noticed that its been awhile since you posted this....did you ever get your problem resolved?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |