edimusrex has asked for the wisdom of the Perl Monks concerning the following question:
I am once again seeking some help (it's been a while which is good...I think?). What I am trying to do it sort a hash in a predetermined order by its value. I am sure there is an easy way to accomplish this but I'm a little stuck on it.
Here's the code thus far :
#!/usr/bin/perl use strict; use warnings; use Net::Telnet::Cisco; my $host = 'voip-cme.compsciresources.com'; my $ssh = Net::Telnet::Cisco->new(Host => $host); $ssh->login('xxxx','xxxx'); my %int; my @output = $ssh->cmd("show ip interface brief"); foreach my $item(@output){ chomp $item; $item =~ s/^\s+//; my($interface,$ip,$ok,$method,$status,$protocol) = split(/\s+/,$it +em); next if !defined $interface or $interface eq 'Interface'; next if $ip eq 'unassigned'; $int{$interface}{ip} = $ip; $int{$interface}{ok} = $ok; $int{$interface}{method} = $method; $int{$interface}{status} = $status; $int{$interface}{protocol} = $protocol; } foreach my $member (keys %int){ print "$member: "; foreach my $mem_value (keys %{$int{$member}}){ print "$mem_value = $int{$member}{$mem_value} "; } print "\n"; }
I would like to order the output in the order in which I fill the hash as listed above, so (ip, ok, method, status, protocol). This is going to eventually be used as a nagios check and it would be great if the output could be in a consistent order.
Thank you for your wisdom
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting a hash in a predetermined order
by choroba (Cardinal) on Nov 17, 2015 at 23:01 UTC | |
Re: Sorting a hash in a predetermined order
by johngg (Canon) on Nov 17, 2015 at 23:13 UTC | |
Re: Sorting a hash in a predetermined order
by dasgar (Priest) on Nov 17, 2015 at 23:33 UTC | |
Re: Sorting a hash in a predetermined order
by BillKSmith (Monsignor) on Nov 18, 2015 at 04:55 UTC | |
Re: Sorting a hash in a predetermined order
by ctilmes (Vicar) on Nov 18, 2015 at 01:48 UTC | |
by Athanasius (Archbishop) on Nov 18, 2015 at 03:18 UTC | |
Re: Sorting a hash in a predetermined order
by edimusrex (Monk) on Nov 18, 2015 at 15:28 UTC | |
Re: Sorting a hash in a predetermined order
by edimusrex (Monk) on Nov 18, 2015 at 15:33 UTC |
Back to
Seekers of Perl Wisdom