#!/usr/bin/perl -wT
use strict;

# Declarations
my $date = '';
my $time = '';
my $name = '';
my $number = '';
my $u_time = '';
my $l_time = '';


# Formats
format PLAIN_TEXT_TOP = 
			Caller ID Log
Name	           Number	     Date / Time
-------------------------------------------------------------
.

format PLAIN_TEXT = 
@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<<<<<<<<
$name,		    $number,	      $l_time
.


# Main shiznit
$^ = 'PLAIN_TEXT_TOP';
$~ = 'PLAIN_TEXT';

while (<STDIN>)  {
	($date, $time, $name, $number, $u_time) = split (/,/);
	$l_time = localtime ($u_time);
	$name =~ s/([A-Z])([A-Z]*)/$1\L$2/g;
	$name =~ s/^O$/Unknown/;
	$name =~ s/^P$/Private/;
	$number =~ s/(\d{3})(\d{3})(\d{4})/\($1\) $2-$3/;
	write;
}
