http://www.perlmonks.org?node_id=883080


in reply to Re: Simple date and time manipulation
in thread Simple date and time manipulation

Ok, I went through the replies just now, and did some google also. For my need I actually do not need to use any modules. I have a very simple requirement! Here is the code I wrote. In this I have put incrtime as 1 sec, but I can put any number of seconds I want, so no issues there!
#!/usr/bin/perl use strict; my $lat = 23.438; my $slon= 68.000; my $elon= 90.000; my $clon = $slon; my $incrlon= 0.01; my $time = time; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +time) ; my $incrtime=1; my $printmon; my $printyear; open OUTFILE,">tropic_of_cancer.gpx" or die \"Cannot open file for wri +ting\n"; print \"Printing Header...\n"; print OUTFILE "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"n +o\"?>\n"; print OUTFILE "<gpx version=\"1.1\" creator=\"MakeTropic\" xmlns=\"htt +p://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/X +MLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GP +X/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"; print OUTFILE "<trk>\n"; print OUTFILE " <name>Tropic of Cancer</name>\n"; while ($clon < $elon) { $printmon = $mon+1; $printyear = $year+1900; print OUTFILE " <trkseg>\n"; printf OUTFILE (" <trkpt lat=\"%.3f\" lon=\"%.3f\">\n", +$lat,$clon); print OUTFILE " <time>$printyear-$printmon-$mday"." +T"."$hour:$min:$sec"."Z"."</time>\n"; print OUTFILE " </trkpt>\n"; $clon=$clon+$incrlon; $time=$time+$incrtime; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( +$time) ; } print OUTFILE " </trkseg>\n"; print OUTFILE " </trk>\n"; print OUTFILE "</gpx>"; close OUTFILE;
It works fast and is tiny.