data file

F

friend.05

What is this "Hide quoted text - Show quoted text" nonsense?




Of course it does, that is the whole purpose. Or how do you suggest to
count the number of occurences if not by replacing the previous number
with the new number?

jue

Hi,

Above code gives me count for each IP+Code combination.

Now I also want to store time of each IP+Code in hash array.

So that later I can look for time if I have IP+Code.
 
T

Ted Zlatanov

f0c> Above code gives me count for each IP+Code combination.

f0c> Now I also want to store time of each IP+Code in hash array.

f0c> So that later I can look for time if I have IP+Code.

I think you want:

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

sub add_time
{
my $byIP = shift @_;
my $key = shift @_;
my $time = shift @_;

push @{$byIP->{$key}}, $time;

print Dumper $byIP;
}

my $data = {};

add_time($data, "123 567", 100);
add_time($data, "123 567", 120);
add_time($data, "123 567", 140);
add_time($data, "234 678", 200);
add_time($data, "345 789", 300);

To get the actual count (you'll rarely need this):

sub get_time_count
{
my $byIP = shift @_;
my $key = shift @_;

return scalar @{$byIP->{$key}};
}

Note how add_time and get_time_count both operate on @{$byIP->{$key}}.
That's the key to the data structure: an array reference, dereferenced
when you need it so.

Ted
 
J

J. Gleixner

Hi,

Above code gives me count for each IP+Code combination.

Now I also want to store time of each IP+Code in hash array.

Really?? What is a 'hash array'?
So that later I can look for time if I have IP+Code.

Thanks for telling us what you want to do. What's your question?

If you understand how to set the value using the above,
but don't know how to set it to another value, then you
might want to start at the beginning and learn about the
variable types, otherwise you'll never really be able to
read or write very useful code.

perldoc perlintro

and for data structures like 'hashes of arrays' look through

perldoc perldsc

Or get/read one of the many books.

http://books.perl.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top