I want to parse a long ns log text file, and I've attempted to write some
perl code to do that. I am a newbie, and I haven't managed to get my code
working.
Basically, the ns file contains information about TCP connections and I want
to create a perl object for each connection, and gather some data. The code
that I created is the following:

package Connection;

sub new {
        my ($class) = @_;
        my $self = {
                _packet_ids=> {},
                _bytes_per_second => [],
                _source_node => undef,
                _destination_node => undef
        };
        bless $self, $class;
        return $self;
}

sub addToBytesPerSecond {
        my ( $self, $currentBytesPerSecond) = @_;
        my $atLocation = $self->{_seconds_counter};
        $self->{_bytes_per_second}[$atLocation] = $currentBytesPerSecond;
        print "";
}

sub printBytesPerSecond {
        my ($self) = @_;
        my $loopCounter = 0;
        my $length = scalar($self->{_bytes_per_second});

        while ($loopCounter < $length) {
                print "$self->{bytes_per_second}[$loopCounter]\n";
                $loopCounter++;
        }
}


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

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

The sourceNode and destinationNode functions work fine. But the
printBytesPerSecond and the addToBytesPerSecond functions do not work.
I can't understand what's wrong with them. Moreover, as you can see I also
want to have a hashtable with the packetIds that have been seen while
parsing, so as to filter duplicate packets. I didn't even attempt that,
because I couldn't understand how to insert a scalar into the hash, and how
to retrieve the value.

I would appreciate any help given.
G.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to