in reply to AoA data merging
The data for run #1:package Point; use strict; use warnings; use Data::Dumper; my @data = (...) #see data_sets below my @new_data; while ( @data ) { my $item = shift @data; my $match; foreach (0 .. $#data ) { if ( $data[$_][0]{X} == @{$item}[-1]->{X} and $data[$_][0]{Y} == @{$item}[-1]->{Y} ) { $match = ['front', $_ ]; last; } if ( $data[$_][-1]{X} == @{$item}[0]->{X} and $data[$_][-1]{Y} == @{$item}[0]->{Y} ) { $match = ['end' , $_ ]; last; } } if ( defined $match ) { if ( @{$match}[0] eq 'front' ) { splice @{$data[@{$match}[1]]},0,1,@{$item}; } else { splice @{$data[@{$match}[1]]},-1,1,@{$item}; } } else { push @new_data,$item; } } print Dumper \@new_data;
my @data = ( [ bless({'X' => '35', 'Y' => '35'}, 'Point'), bless({'X' => '36', 'Y' => '36'}, 'Point'), bless({'X' => '37', 'Y' => '37'}, 'Point'), bless({'X' => '38', 'Y' => '38'}, 'Point'), ], [ bless({'X' => '1', 'Y' => '1'}, 'Point'), bless({'X' => '2', 'Y' => '2'}, 'Point'), bless({'X' => '3', 'Y' => '3'}, 'Point'), bless({'X' => '4', 'Y' => '4'}, 'Point'), ], [ bless({'X' => '39', 'Y' => '39'}, 'Point'), bless({'X' => '40', 'Y' => '40'}, 'Point'), bless({'X' => '41', 'Y' => '41'}, 'Point'), bless({'X' => '42', 'Y' => '47'}, 'Point'), ], [ bless({'X' => '7', 'Y' => '7'}, 'Point'), bless({'X' => '8', 'Y' => '8'}, 'Point'), bless({'X' => '9', 'Y' => '9'}, 'Point'), bless({'X' => '10', 'Y' => '10'}, 'Point'), ], [ bless({'X' => '4', 'Y' => '4'}, 'Point'), bless({'X' => '5', 'Y' => '5'}, 'Point'), bless({'X' => '6', 'Y' => '6'}, 'Point'), bless({'X' => '7', 'Y' => '7'}, 'Point'), ], [ bless({'X' => '22', 'Y' => '32'}, 'Point'), bless({'X' => '33', 'Y' => '33'}, 'Point'), bless({'X' => '34', 'Y' => '34'}, 'Point'), bless({'X' => '35', 'Y' => '35'}, 'Point'), ], [ bless({'X' => '42', 'Y' => '47'}, 'Point'), bless({'X' => '43', 'Y' => '43'}, 'Point'), bless({'X' => '44', 'Y' => '43'}, 'Point'), bless({'X' => '45', 'Y' => '45'}, 'Point'), ], );
and the results
$VAR1 = [ [ bless( { 'X' => 1, 'Y' => '1' }, 'Point' ), bless( { 'X' => '2', 'Y' => '2' }, 'Point' ), bless( { 'X' => '3', 'Y' => '3' }, 'Point' ), bless( { 'X' => 4, 'Y' => 4 }, 'Point' ), bless( { 'X' => '5', 'Y' => '5' }, 'Point' ), bless( { 'X' => '6', 'Y' => '6' }, 'Point' ), bless( { 'X' => 7, 'Y' => 7 }, 'Point' ), bless( { 'X' => '8', 'Y' => '8' }, 'Point' ), bless( { 'X' => '9', 'Y' => '9' }, 'Point' ), bless( { 'X' => 10, 'Y' => '10' }, 'Point' ) ], [ bless( { 'X' => 22, 'Y' => '32' }, 'Point' ), bless( { 'X' => '33', 'Y' => '33' }, 'Point' ), bless( { 'X' => '34', 'Y' => '34' }, 'Point' ), bless( { 'X' => 35, 'Y' => 35 }, 'Point' ), bless( { 'X' => '36', 'Y' => '36' }, 'Point' ), bless( { 'X' => '37', 'Y' => '37' }, 'Point' ), bless( { 'X' => 38, 'Y' => '38' }, 'Point' ) ], [ bless( { 'X' => 39, 'Y' => '39' }, 'Point' ), bless( { 'X' => '40', 'Y' => '40' }, 'Point' ), bless( { 'X' => '41', 'Y' => '41' }, 'Point' ), bless( { 'X' => 42, 'Y' => 47 }, 'Point' ), bless( { 'X' => '43', 'Y' => '43' }, 'Point' ), bless( { 'X' => '44', 'Y' => '43' }, 'Point' ), bless( { 'X' => 45, 'Y' => '45' }, 'Point' ) ] ];
and with your data the results were :
$VAR1 = [ [ bless( { 'X' => '2289563.40820205', 'Y' => '512818.142015762' }, 'Point' ), bless( { 'X' => '2289542.5', 'Y' => '512756.0625' }, 'Point' ), bless( { 'X' => '2289188.03442014', 'Y' => '510403.174475172' }, 'Point' ), bless( { 'X' => '2289106.00673453', 'Y' => '509893.307668147' }, 'Point' ), bless( { 'X' => '2289299.27685392', 'Y' => '507531.897507685' }, 'Point' ), bless( { 'X' => '2289290.30567314', 'Y' => '507448.506452598' }, 'Point' ), bless( { 'X' => '2289282.72943502', 'Y' => '507410.155776398' }, 'Point' ), bless( { 'X' => '2289149', 'Y' => '507002.0625' }, 'Point' ), bless( { 'X' => '2289055.31527948', 'Y' => '506731.474946477' }, 'Point' ), bless( { 'X' => '2289012.5', 'Y' => '506607.8125' }, ' Point' ), bless( { 'X' => '2288907', 'Y' => '506360.3125' }, 'Point' ), bless( { 'X' => '2288891.13335288', 'Y' => '506310.118972175' }, 'Point' ), bless( { 'X' => '2288451.69937281', 'Y' => '505554.395479093' }, 'Point' ), bless( { 'X' => '2288410.26157533', 'Y' => '505497.135963316' }, 'Point' ), bless( { 'X' => '2288373.62815415', 'Y' => '505449.841277223' }, 'Point' ), bless( { 'X' => '2287631.5', 'Y' => '503533.9375' }, 'Point' ), bless( { 'X' => 2287593, 'Y' => 503471 }, 'Point' ), bless( { 'X' => '2287498.5', 'Y' => '502968.75' }, 'Point' ), bless( { 'X' => '2287529.54227622', 'Y' => '502752.130034798' }, 'Point' ), bless( { 'X' => '2287571.41650288', 'Y' => '502527.884072168' }, 'Point' ) ] ];
-enlil
|
|---|