Hello all! I've a csv file like :
City sunshine Temperature
Ajaccio 2790 14.7
Lyon 2072 11.4
Marseille 2763 14.2
Brest 1729 10.8
Lille 1574 9.7
Paris 1833 11.2
Strasbourg 1685 9.7
I'd like to print just the city+temperature with the highest and the lowest temperature. How?
City sunshine Temperature
Ajaccio 2790 14.7
Lyon 2072 11.4
Marseille 2763 14.2
Brest 1729 10.8
Lille 1574 9.7
Paris 1833 11.2
Strasbourg 1685 9.7
I'd like to print just the city+temperature with the highest and the lowest temperature. How?
Perl:
#!/usr/bin/perl
use warnings;
use diagnostics;
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 0;
#definyn arrays for temperatures, files and city
my (@temp, @file, @ville);
my ($file, $line);
my %temperature;
$file = "temperatures.csv";
#I don't consider the first line of the file and I put just the city and its temperture in two arrays
open (F, "<", $file);
while(defined($line = <F>)) {
if ( $. > 1 ) {
@file = split(/ /, $line);
push(@ville, $file[0]);
push(@temp, $file[2]);
}
}
#then I create the hash and print what there's inside
@temperature{@ville} = @temp;
print '%temperature : ', Dumper(\%temperature), "\n";
#now I "order" the hash by value
foreach my $value (sort {$temperature{$a} <=> $temperature{$b} || ($a cmp $b) } keys %temperature)
{
print " the city of $value and its temperature : $temperature{$value}\n";
}
close(F);
#is there a way to print ONLY the first and the last element in order to have the highest and the lowest temperature?