or if you rather just retain the first and last time for each key for which there is more than one time:
use strict;
use warnings;
use Data::Dumper;
my %HoA;
while (<DATA>)
{
chomp;
next if ! length $_;
my ($key, $time) = split ",";
if (! $HoA{$key})
{push @{$HoA{$key}}, $time;}
elsif (@{$HoA{$key}} == 1)
{push @{$HoA{$key}}, $time;}
else
{${@{$HoA{$key}}}[1] = $time;}
}
print Dumper (%HoA);
__DATA__
KEY1, 07/25/05 09:04:36
KEY2, 07/25/05 09:04:36
KEY2, 07/25/05 09:04:37
KEY2, 07/25/05 09:05:49
KEY2, 07/25/05 09:05:50
KEY3, 07/25/05 09:05:50
$VAR1 = 'KEY2';
$VAR2 = [
' 07/25/05 09:04:36',
' 07/25/05 09:05:50'
];
$VAR3 = 'KEY1';
$VAR4 = [
' 07/25/05 09:04:36'
];
$VAR5 = 'KEY3';
$VAR6 = [
' 07/25/05 09:05:50'
];
Perl is Huffman encoded by design.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.