#!/usr/bin/perl # Copyright : http://www.fsf.org/copyleft/gpl.html # Author 作者 : 積丹尼 Dan Jacobson -- http://jidanni.org/ # Created On : Wed Jun 7 01:52:02 2017 # Last Modified On: Thu Jun 8 15:43:35 2017 # Update Count : 34 # 將某 TXT 轉 GPX use strict; use warnings FATAL => q(all); use XML::TreePP; my $tree; while (<>) { s/ (號)/$1/; my @F = split; next unless $#F > 2; die unless $#F == 6; next if $F[4] eq '東經度'; push @{ $tree->{gpx}->{wpt} }, { '-lat' => ll( $F[5] ), '-lon' => ll( $F[4] ), name => $F[1], desc => "" }; } print XML::TreePP->new( indent => 2, first_out => ['name'] )->write($tree); sub ll { for (@_) { /^(\d+)度(\d+)分([0-9.]+)秒$/ || die; return sprintf "%.6f", ( $3 / 60 + $2 ) / 60 + $1; } }