#!/usr/local/bin/perl -w use strict; use Getopt::Long; GetOptions( \my %opts, "tour=s" ); use YAML qw( Load Dump ); my @tours = ( ); my $tour; my $tracks = Load join "", <>; my $tour_split_secs = 60 * 60 * 5; for my $point ( @$tracks ) { # next tour? if( defined $tour and $point->{ "time" } > $tour->{ end } + $tour_split_secs ) { undef $tour; } # start new tour? if( !defined $tour ) { $tour = { start => $point->{ "time" }, points => [] }; push @tours, $tour; } # next point in current tour $tour->{ end } = $point->{ "time" }; push @{ $tour->{ points } }, $point; } if( $opts{ tour } ) { print Dump( $tours[ $opts{ tour } - 1 ]->{ points } ); } else { my $idx = 1; for my $tour ( @tours ) { printf "tour %02d: %s - %s (%d)\n", $idx, map( { scalar localtime $_ } ( $tour->{ start }, $tour->{ end } ) ), scalar @{ $tour->{ points } }; $idx++; } }