Greg@Work has asked for the wisdom of the Perl Monks concerning the following question:
I could use a bit of help with my Perl code - specifically, I'm trying to sort a hash... and it does not seem to be cooperating. The hash is built here, comprised of 2 elements - Severity and Note. read in from an xml configuration file, and added to the hash if the uploaded files contain the text the health check is configured to seek out.
my %Relevant; foreach my $e (@{$data->{check}}) { #first go though the health checks looking to see if we have r +elevant checks for this event code if ($e->{relevant_events} =~ $FindEvent ) { $WantedFile = $e->{filename}; $WantedText = $e->{find}; #scan the files for the text we are after DXWanted(); if ($FileStatus == 1) { $Relevant{$e->{severity}} = $e->{note}; $FileStatus = 0; } }
Later in the code, I want to sort the hash descending by the numerical value of severity:
foreach my $name (sort { $Relevant{$b} <=> $Relevant{$a} } keys %Relev +ant) { $RESULTS = $RESULTS . "Severity: " . $name . "\n" . $Relevant{ +$name} . "\n\n" }
Can anyone spot what I've done wrong? Thanks very very much,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: My Perl-foo... SORT is not strong
by Anonymous Monk on Mar 19, 2015 at 14:55 UTC | |
by Greg@Work (Initiate) on Mar 19, 2015 at 15:21 UTC | |
by Anonymous Monk on Mar 19, 2015 at 15:35 UTC | |
by Greg@Work (Initiate) on Mar 19, 2015 at 16:50 UTC | |
by choroba (Cardinal) on Mar 19, 2015 at 16:53 UTC | |
| |
by marinersk (Priest) on Mar 19, 2015 at 15:40 UTC |