How about the following code:
#!perl use strict; use warnings; use Data::Dumper; my %monthLookup = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6, Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12 ); sub CompDates($$) { my ($first, $second) = @_; $first = [($first =~ m!(\d{2])/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\ +d{2})!)]; $second = [($second =~ m!(\d{2])/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\ +d{2})!)]; $first->[1] = $monthLookup{$first->[1]}; $second->[1] = $monthLookup{$second->[1]}; return (($first->[0] <=> $second->[0]) || ($first->[1] <=> $second->[1]) || ($first->[2] <=> $second->[2]) || ($first->[3] <=> $second->[3]) || ($first->[4] <=> $second->[4]) || ($first->[5] <=> $second->[5]) ); } my %users; while (<DATA>) { my ($user, $time, $primary, $secondary, $views, $clicks, $sessions, $mode, $zip) = split; if ($users{$user}) { if (CompDates($users{$user}->{LastVisitTime}, $time) < 0) { $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__ 0ce46e475f94ecb9 01/Jan/2003:16:00:08 Computers Computers 1 0 1 no_mod +e 00000 188c0530ac92475a 01/Jan/2003:16:00:02 Computers Computers 1 1 1 no_mod +e 44614 189a4a75d0cbad03 01/Jan/2003:16:00:01 No_category No_category 1 0 1 no +_mode 00000 189e45678964fcf6 01/Jan/2003:16:00:07 Electronics Electronics 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
This should do it, as far as I understood your problem. Post a reply if it does not.
Cheers, CombatSquirrel.

In reply to Re: Merging Hashes adding multiple values for keys, and replacing others by CombatSquirrel
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.