Hi, I use geo::gpx to read GPS data. That works okay when i loop at the dumper output. Then i got stuck by the knowledge. How do i loop through "$tracks" and access eg. 'ele' to generate the average elevation per track like :

Output i'd like to have

Average elevation Track 1 = 72 Track 2 = 61

My Code

use Geo::Gpx; open $fh, "W20120129101405.gpx" ; my $gpx = Geo::Gpx->new( input => $fh ); my $tracks = $gpx->tracks(); print Dumper ($tracks);

Data Dump

-- OUTPUT --
$VAR1 = = [ { 'name' => 'Track 1', 'segments' => [ { 'points' => [ { 'lat' => '54.5182217145253', 'ele' => '73.0', 'lon' => '-2.62191579018834' }, { 'lat' => '54.1507759448355', 'lon' => '-3.05774931478646' 'ele' => '71.0', }, { 'lat' => '54.6016296784874', 'lon' => '-3.40418920968631' 'ele' => '72.0', } ] }, { 'points' => [ { 'lat' => '54.6862790450185', 'lon' => '-3.68760108982739' 'ele' => '63.0', } ] } ] }, { 'name' => 'Track 2', 'segments' => [ { 'points' => [ { 'lat' => '54.9927807628549', 'lon' => '-4.04712811256436' 'ele' => '60.0', }, { 'lat' => '55.1148395198045', 'lon' => '-4.33623533555793' 'ele' => '61.0', }, { 'lat' => '54.6214174046189', 'lon' => '-4.26293674042878' 'ele' => '62.0', }, { 'lat' => '55.0540816059084', 'lon' => '-4.42261020671926' 'ele' => '59.0', }, { 'lat' => '55.4451622411372', 'lon' => '-4.32873765338' 'ele' => '63.0', } ] } ] } ];

In reply to how to access GPX data by geogpx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.