Gavin has asked for the wisdom of the Perl Monks concerning the following question:
The actual out put and desired out put are shown beow#!usr/bin/perl -W use strict;# forces predeclaration of variables use diagnostics;#diagnostic tools #use Data::Dumper::Simple;#print out contents of variables use porter; # load the porter stemmer module my %hashA = ( 'accord newton second' => 80, 'acceler smaller greater' => 78, 'addit law motion' => 56, 'meant bodi act forc'=> 55, ); foreach my $key(keys %hashA){ #print "$key $hashA{$key}\n"; } my %hashB = (2 => 'addit law motion', 3 => 'accord newton second', 4 => 'meant bodi act forc', 5 => 'acceler smaller greater', ); foreach my $key(keys %hashB){ #print "$key $hashB{$key}\n"; } my @sorted_scores = keys %hashA;#keys from hash A foreach (@sorted_scores){# this gives sorted text #print "$_\n"; } my @sorted_words = map { $hashA{$_} } @sorted_scores;#sorted text foreach (@sorted_words){ #print "$_\n";# this gives the scores sorted out } my %hashC = (2 => "In addition to ", 3 => "According to Newton", 4 => "It also meant that whenever ", 5 => "The acceleration is", ); my (@line_Numbers); my %reversehashB = reverse %hashB; @line_Numbers = map { $reversehashB {$_} }@sorted_scores; foreach (@line_Numbers){ #print "$_\n"; } foreach (@line_Numbers){ print ($_,' ', $hashC{$_}, "\n"); }
Actual Data Out 4 It also meant that whenever 5 The acceleration is 3 According to Newton 2 In addition to Desired Data Out 3 According to Newton 5 The acceleration is 2 In addition to 4 It also meant that whenever
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retaining Insertion order throughout when using “map”
by johngg (Canon) on Apr 13, 2006 at 10:59 UTC | |
|
Re: Retaining Insertion order throughout when using “map”
by lima1 (Curate) on Apr 13, 2006 at 09:36 UTC | |
|
Re: Retaining Insertion order throughout when using “map”
by Limbic~Region (Chancellor) on Apr 13, 2006 at 12:48 UTC |