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


In reply to Sorting a hash in a predetermined order by edimusrex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.