In Python, i could use dictionary to do that

In Perl, a "dictionary" is called a hash.

As you have multiple aircraft, you cannot use the rowids to determine consecutive coordinates for a given aircraft (unless there are always and only 2), so I've used a hash of arrays of hashes to accumulate the data in:

$planes{ $aid }[ n ]{ ... };

This print the headings for each aircraft as it reads the data:

C:\test>junk53 Aircraft: 599 heading: 0.000 Aircraft: 591 heading: 90.000 Aircraft: 599 heading: 0.000 Aircraft: 591 heading: 90.000

Would've been nice if the sample contained some heading changes, and I'm somewhat suspicious of the exact 90° difference in the aircraft headings, so check the math. but this should get you started:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @headers = split ' ', do{ my $raw = <DATA>; $raw =~ tr[",][ ]; $raw + }; #" my %planes; while( my $line = <DATA> ) { $line =~ tr[",][ ]; #" my @fields = split ' ', $line; my $rowid = shift @fields; my $aid = shift @fields; my %row; @row{ @headers } = @fields; push @{ $planes{ $aid } }, \%row; next unless @{ $planes{ $aid } } > 1; my $lat1 = $planes{ $aid }[ -2 ]{ latitude }; my $lat2 = $planes{ $aid }[ -1 ]{ latitude }; my $dlat = $lat2 - $lat1; my $lon1 = $planes{ $aid }[ -2 ]{ longitude }; my $lon2 = $planes{ $aid }[ -1 ]{ longitude }; my $dlon = $lon2 - $lon1; my $y = sin( $dlon / 180 ) * cos( $lat2 /180 ); my $x = cos( $lat1 /180 ) * sin( $lat2/180 ) - sin( $lat1/180 ) * +cos( $lat2/180 ) * cos( $dlon/180 ); printf "Aircraft: %d heading: %6.3f\n", $aid, atan2( $y, $x ) * 57 +.2957795; } __DATA__ "rowid","aircraft_id","actual_date_time","latitude","longitude","radio +_altitude","ground_speed","thrust_engine_1","thrust_engine_2" 3828994,599,2012-11-04 14:00:00,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828995,591,2012-11-04 14:00:00,51.47598267,-0.435331702,-0.875,0.0,0. +066208174,0.068682498,0.913095793953437657822846430541224159086453865 +40627114668956,4.8940906898850944664550883969746212941234464464906348 +3492349 3828996,599,2012-11-04 14:00:01,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828997,591,2012-11-04 14:00:01,51.47598267,-0.435331702,-0.75,0.0,0.0 +64970428,0.068682498,0.9055060385715144395793861983988312690635603870 +3789731965392,4.92096836684002218971971504299700119099094370033875757 +916224 3828998,599,2012-11-04 14:00:02,51.47592545,-0.437049866,-9.0,2.0,0.04 +4653355,0.041778761,1.74208527619370935228499282740898271690901934191 +164070390564,15.22092881857486030932218666006017736321211426212568671 +811012 3828999,591,2012-11-04 14:00:02,51.47598267,-0.435331702,-0.625,0.0,0. +066208174,0.068682498,0.913095793953437657822846430541224159086453865 +40627114668956,4.8940906898850944664550883969746212941234464464906348 +3492349

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Calculate aircraft headings from GPS data for google kml display by BrowserUk
in thread Calculate aircraft headings from GPS data for google kml display by hujunsimon

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.