Thanks a lot CombatSquirrel, that was very close to what I'm looking for. I did
rewrite the date part, as I have decided to use unix timestamp, as that simplifies things some.
And may I say you RoCk! here's, the updated code:
#!/usr/bin/perl # use warnings; use strict; use Data::Dumper; sub apache2epoch() { use POSIX; my $datetime=$ARGV[0]; my $i=0; my %months; %months = map { $_ => $i++ } ("Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"); $_[0] =~ m((\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)); return &mktime($6,$5,$4,$1,$months{$2},$3-1900,0,0,-1); } + + my %users; while (<DATA>) { my ($user, $time, $primary, $secondary, $views, $clicks, $sessions, $mode, $zip) = split; if ($users{$user}) { if ((&apache2epoch($time))-(&apache2epoch(($users{$user}->{LastVisitTi +me}))) >1800 ) { $users{$user}->{LastVisitTime} = $time; } } else { $users{$user}->{LastVisitTime} = $time; $users{$user}->{PrimaryCategory} = $primary; $users{$user}->{SecondaryCategory} = $secondary; $users{$user}->{MarketingMode} = $mode; $users{$user}->{ZIP} = $zip; } $users{$user}->{PageViews} += $views; $users{$user}->{MerchantClicks} += $clicks; $users{$user}->{Sessions} += $sessions; } print Dumper(\%users); + __DATA__ 188c0530ac92475a 01/Jan/2003:16:00:02 Computers Computers 1 1 1 no_mod +e 44614 0ce46e475f94ecb9 01/Jan/2003:16:00:08 Computers Computers 1 0 1 no_mod +e 00000 189e45678964fcf6 01/Jan/2003:16:00:07 Electronics Electronics 1 0 1 no +_mode 00000 189a4a75d0cbad03 01/Jan/2003:16:00:01 No_category No_category 1 0 1 no +_mode 00000 18a416ba3d3c7a8d 01/Jan/2003:16:00:12 No_category No_category 2 0 1 no +_mode 00000 18aa11982e30e1ef 01/Jan/2003:16:00:07 No_category No_category 1 0 1 no +_mode 00000 0ce46e475f94ecb9 01/Jan/2003:17:00:08 Computers Computers 1 0 1 no_mod +e 00000 189a4a75d0cbad03 01/Jan/2003:17:00:01 No_category No_category 1 0 1 no +_mode 00
btw, on the CompDates sub, if I encounter the same $user it gets the errors
Use of uninitialized value in numeric comparison (<=>) at ./overall.pl line 28, <DATA> line 7.
thanks again CombatSquirrel, and Cheers to you too

~vili
sniff sniff 802.11

In reply to Re: Re: Merging Hashes adding multiple values for keys, and replacing others by vili
in thread Merging Hashes adding multiple values for keys, and replacing others by vili

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.