Hi,

   open(MYINPUTFILE, "<access.log");
  while(<MYINPUTFILE>)
  { 
           # Good practice to store $_ value because # subsequent operations may change it.
            my($line) = $_;
       # Good practice to always strip the trailing # newline from the line.
            chomp($line);
         my($time, $elapsed, $remotehost, $csp, $bytes, $method, $url, $user) = split(' ', $line);
        # Print the line to the screen and add a newline
         print "$user - $bytes\n";
}

ACCESS.LOG is a text file having details of time,elapsed,remotehost,bytes,method,url and the userid .

From the access file,i want mainly the userid and the bytes and i printing that value

 print "$user - $bytes\n";

From upto its ok.

I want to store millions of userid($user) values and their corresonding bytes($bytes) values into an dynamic array.

How i can store this values into an dynamic array?

please help me

with regards,
santhanalakshmi

What exactly are you asking? Perl arrays are not like C++ arrays, they can grow and shrink in size dynamically.

my @array;

This declares an empty array, whose size is zero. To add things to array, most common operations push and unshift.

push (@ARRAY,  $VALUE);

puts VALUE onto the end of ARAAY, and increases the size of ARRAY by one.

Unshift will do the same thing, only to the begining of an array.

The corresponding functions to remove from an array are pop and shift.

So that's it about arrays. But I just realized that you want userids and bytes to correspond, so what you actually want is a hash, which stores groups of key-value pairs. my %hash declares an empty hash.

%hash = (
key1 => value1,
key2 => value2,
key3 => value3 #no comma on last value!!!
);

You can access the the values of the hash like this:

$hash{key};  #Note $ sign, not %!

This returns the value that corresponds to key. To add new key-value pair to hash, do like this:

$hash{$key} = $value;

I hope this helps, let me know if you need more assistance.

What exactly are you asking? Perl arrays are not like C++ arrays, they can grow and shrink in size dynamically.

my @array;

This declares an empty array, whose size is zero. To add things to array, most common operations push and unshift.

push (@ARRAY,  $VALUE);

puts VALUE onto the end of ARAAY, and increases the size of ARRAY by one.

Unshift will do the same thing, only to the begining of an array.

The corresponding functions to remove from an array are pop and shift.

So that's it about arrays. But I just realized that you want userids and bytes to correspond, so what you actually want is a hash, which stores groups of key-value pairs. my %hash declares an empty hash.

%hash = (
key1 => value1,
key2 => value2,
key3 => value3 #no comma on last value!!!
);

You can access the the values of the hash like this:

$hash{key};  #Note $ sign, not %!

This returns the value that corresponds to key. To add new key-value pair to hash, do like this:

$hash{$key} = $value;

I hope this helps, let me know if you need more assistance.

hi,

Its working fine.I have one more question."Access.txt" is a text file where i get the userid and the bytes.When i ran my script perl process.pl,i takes more than half an hour .Because my "Access.txt" file is a huge file.

There is an possibility to split my "Access.txt" into small small segments.If is it possible means,please tell me the way.

Access.txt file size can be in MB or GB
(or)

How to minimize the running process?please help me

Regards,
Santhanlakshmi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.