Skip to content

Instantly share code, notes, and snippets.

@wolfjohns
Created March 28, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfjohns/fee1bf921011b5fb8c523a47874b053e to your computer and use it in GitHub Desktop.
Save wolfjohns/fee1bf921011b5fb8c523a47874b053e to your computer and use it in GitHub Desktop.
geekuni Topic 7 q10
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump 'pp';
use feature 'say';
use Getopt::Long;
use Text::CSV qw(csv);
####
#FILL ME IN!!
sub parse_airports {
my $filename = shift;
my $airports = csv(
in => $filename,
headers => 'auto');
return $airports;
}
my $filename = '/home/student/perl-basic/topic-07/iata_airports.csv';
my $number = 1;
my $matching;
my $latitude;
my $longitude;
GetOptions (
'filename:s' => \$filename,
'number:i' => \$number,
'matching:s' => \$matching,
'latitude:f' => \$latitude,
'longitude:f' => \$longitude,
) or die "Invalid options passed $0\n";
####
my $rah_airports = parse_airports($filename);
my $rah_airports_found = [];
if ($matching) {
say "Up to $number airports matching $matching in $filename:";
}
elsif ($latitude && $longitude) {
say "Up to $number airports near [$latitude, $longitude] in $filename:"
}
else {
say "Must have at least --matching, or --latitude and --longitude as arguments";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment