#!usr/bin/perl -W use strict;# forces predeclaration of variables use diagnostics;#diagnostic tools my %hashA = ( 'accord newton second' => 80, 'acceler smaller greater' => 78, 'addit law motion' => 56, 'meant bodi act forc'=> 55, ); my %hashB = (2 => 'addit law motion', 3 => 'accord newton second', 4 => 'meant bodi act forc', 5 => 'acceler smaller greater', ); my %hashC = (2 => "In addition to ", 3 => "According to Newton", 4 => "It also meant that whenever ", 5 => "The acceleration is", ); # this is not a sorted array!!! my @sorted_scores = keys %hashA;#keys from hash A # still not sorted my @sorted_words = map { $hashA{$_} } @sorted_scores;#sorted text my (@line_Numbers); # this sorts the key numerically @line_Numbers = sort {$a <=> $b} keys %hashB; # and prints your desired output foreach (@line_Numbers){ print ($_,' ', $hashC{$_}, "\n"); }
In reply to Re: Retaining Insertion order throughout when using “map”
by lima1
in thread Retaining Insertion order throughout when using “map”
by Gavin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |