sorry this my first post im trying to sort a list by user name and count the different functions they have done with time they did each function. here is example of what a file looks like:
user;work;workgroup;function;start time;comp time
user1;ef1;1;1;10/12/09 8:00;10/12/09 10:00
user1;ef2;1;1;10/12/09 11:00;10/12/09 12:00
user1;ef3;1;2;10/12/09 13:00:00;10/12/09 15:00
user2;efs1;1;1;10/12/09 8:00;10/12/09 10:00
user2;efs2;1;2;10/12/09 10:00;10/12/09 15:00
user2;efs3;1;2;10/12/09 16:00;10/12/09 18:00
I would expect my output to look like this:
user function count
user1 1 2 3hrs0min
user1 2 1 2hrs0min
user2 1 1 2hrs0min
user2 2 2 9hrs0min
I hope this make sense. here is what i have tried:
<IN> would be the example file above
for (<IN>) {
chomp;
my ($user,$work,$wg,$func,$start_time, $comp_time) = split(";", $_);
if (!$seen{$user}{$work}) {
$seen{$user}{$work}++;
if ($func == 1){
$funcone++;
push(@one, $
}
if ($func == 2){
$functwo++;
}
if ($func == 3){
$functhree++;
}
}
if ($funcone ne ""){
print "$user $func $funcone\n";
}
if ($functwo ne ""){
print "$user$func $functwo\n";
}
if ($functhree ne ""){
print "$user $func $functhree\n";
}
}
ive also tried data dumper. it works but i cant get it print out like i want. here is the data dumper code:
#!/usr/bin/perl
use strict;
use warnings;
use Data:umper;
# Make Data:umper pretty
$Data:umper::Sortkeys = 1;
$Data:umper::Indent = 1;
# Set maximum depth for Data:umper, zero means unlimited
$Data:umper::Maxdepth = 0;
my %seen = ();
my %func_counts = ();
while( <DATA> ){
chomp;
my ($user,$work,$wg,$func,$start_time,$comp_time) = split(";", $_);
unless( $seen{$user}{$work} ){
$seen{$user}{$work} ++;
$func_counts{$user}{$func} ++;
}
}
print Dumper \%seen, \%func_counts;
__DATA__
user1;ef1;1;1;10/12/09 8:00;10/12/09 10:00
user1;ef2;1;1;10/12/09 11:00;10/12/09 12:00
user1;ef3;1;2;10/12/09 13:00:00;10/12/09 15:00
user2;efs1;1;1;10/12/09 8:00;10/12/09 10:00
user2;efs2;1;2;10/12/09 10:00;10/12/09 15:00
user2;efs3;1;2;10/12/09 16:00;10/12/09 18:00
user;work;workgroup;function;start time;comp time
user1;ef1;1;1;10/12/09 8:00;10/12/09 10:00
user1;ef2;1;1;10/12/09 11:00;10/12/09 12:00
user1;ef3;1;2;10/12/09 13:00:00;10/12/09 15:00
user2;efs1;1;1;10/12/09 8:00;10/12/09 10:00
user2;efs2;1;2;10/12/09 10:00;10/12/09 15:00
user2;efs3;1;2;10/12/09 16:00;10/12/09 18:00
I would expect my output to look like this:
user function count
user1 1 2 3hrs0min
user1 2 1 2hrs0min
user2 1 1 2hrs0min
user2 2 2 9hrs0min
I hope this make sense. here is what i have tried:
<IN> would be the example file above
for (<IN>) {
chomp;
my ($user,$work,$wg,$func,$start_time, $comp_time) = split(";", $_);
if (!$seen{$user}{$work}) {
$seen{$user}{$work}++;
if ($func == 1){
$funcone++;
push(@one, $
}
if ($func == 2){
$functwo++;
}
if ($func == 3){
$functhree++;
}
}
if ($funcone ne ""){
print "$user $func $funcone\n";
}
if ($functwo ne ""){
print "$user$func $functwo\n";
}
if ($functhree ne ""){
print "$user $func $functhree\n";
}
}
ive also tried data dumper. it works but i cant get it print out like i want. here is the data dumper code:
#!/usr/bin/perl
use strict;
use warnings;
use Data:umper;
# Make Data:umper pretty
$Data:umper::Sortkeys = 1;
$Data:umper::Indent = 1;
# Set maximum depth for Data:umper, zero means unlimited
$Data:umper::Maxdepth = 0;
my %seen = ();
my %func_counts = ();
while( <DATA> ){
chomp;
my ($user,$work,$wg,$func,$start_time,$comp_time) = split(";", $_);
unless( $seen{$user}{$work} ){
$seen{$user}{$work} ++;
$func_counts{$user}{$func} ++;
}
}
print Dumper \%seen, \%func_counts;
__DATA__
user1;ef1;1;1;10/12/09 8:00;10/12/09 10:00
user1;ef2;1;1;10/12/09 11:00;10/12/09 12:00
user1;ef3;1;2;10/12/09 13:00:00;10/12/09 15:00
user2;efs1;1;1;10/12/09 8:00;10/12/09 10:00
user2;efs2;1;2;10/12/09 10:00;10/12/09 15:00
user2;efs3;1;2;10/12/09 16:00;10/12/09 18:00