CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
inserting to hash and calculating !!!!

 



jeffersno1
Novice

May 31, 2012, 12:34 AM

Post #1 of 2 (850 views)
inserting to hash and calculating !!!! Can't Post

Hi All,

Wondered if someone could me here, I support a data pass system where users purchase a data pass to browse the internet, These passes have an allocated data allowance (ranging from 50MB to 10GB) I'm trying to get the average pass usage for each pass name.

Each pass will expire by Volume or Time and the logs look like this:

for pass expiry
date,passexpiry,Customer number,Pass name,uk_number,AMOUNT OF PASS USED,pass expiry datetime
2012-05-29_00:01:10:353,passExpiryTime,440000000000,PASS00034,UK_8713649,1199045388,2012-05-26_00:01:11
2012-05-29_00:01:11:408,passExpiryTime,440000000000,PASS00030,UK_8733042,58458706,2012-05-28_00:01:12

for pass expiry by volume the logs are different
date,Customer number,passexpiry,PASS NAME,uk_number,pass expiry datetime,AMOUNT OF PASS USED
2012-05-29_00:03:52:821,440000000000,passExpiryVolume,PASS00016,UK_8558084,2012-06-10_14:36:02,2147484755
2012-05-29_00:03:59:986,440000000000,passExpiryVolume,PASS00017,UK_8726029,2012-05-30_11:11:10,1073743201

I have all pass info available (name & volume allocated)
pass_name vol_allocated_bytes
PASS00034 2147483648
PASS00030 10485760
PASS00016 2147483648
PASS00017 10485760

Ideally I'd like to get a print out like:
PASS NAME VOL_ALLOCATED AVERAGE_VOL_USED
PASS00034 2147483648 1965088868
PASS00030 10485760 10485560

Questions:
1- How do i pass the VOL ALLOCATED to the same array or hash where the pass name and VOL used will be?

Here is an attempt!!!

Code
push(@PASS00034 ,"2147483648"); 
push(@PASS00030,"10485760");
push(@PASS00016,"2147483648");



This is what i have so far


Code
#!/usr/bin/perl -w 
#use strict;
use warnings;

my $pass_file = '/export/home/otpuser/pass_expiry';
open my $fh, '<', $pass_file or die "cant open $!\n";

while (my $line = <$fh>) {
chomp($line);
if (length($line) > 0)
{
@lineArray=split(",",$line);
if ( $lineArray[1] =~ /passExpiryTime/ )
{
$resultsHash{$lineArray[3]}=$lineArray[5];
}
}
}


Any suggestions would be greatly appreciated.

Thanks

Jeffers


FishMonger
Veteran / Moderator

May 31, 2012, 6:56 AM

Post #2 of 2 (844 views)
Re: [jeffersno1] inserting to hash and calculating !!!! [In reply to] Can't Post

You could use a HoH (Hash-of-Hashes) where the outer keys are the pass name's and the next level keys will be the vol allocated bytes and the amount used. The value of the amount used will be a ref to an array of the amounts used and you'll use that array to calculate the average.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives