Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found