in reply to How to create histogram
First, some examples of what you have, what you want, and what you have tried would be very helpful.
One of my favorite ways to count items is with a hash, as in this example:
Output is:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # Assuming these are [ in, out ] my @travel_times = ( [ 1, 5 ], [ 2, 5 ], [ 20, 15 ], ); my %count; foreach my $time (@travel_times) { $count{in }{ $time->[0] }++; $count{out}{ $time->[1] }++; } print Dumper \%count;
$VAR1 = { 'out' => { '15' => 1, '5' => 2 }, 'in' => { '1' => 1, '2' => 1, '20' => 1 } };
|
|---|