Thanks folks for all your replies! its really made my day!

as you've probably guessed its some of the concepts i'm struggling with.

what this code does below seems to do is sort my hash by key alphabetically it then (i think) sorts by the value in {tag} which groups all the records which have the same value in {tag} together for me.

I want to add another 2 sorts.

1. I want to be to pick out a value(53) in {tag} and group my records by that, which will be processed by the foreach loop last so it becomes the last lines in my HTML output.

2. The last group/sort of my hash is pick out this condition in $my_server_hash{$server}{ADMINS} =~ s/$account/FOUND:; and group all those trues togther and make this the second last lines in my HTML.

I include a sample hash.

my %server_hash = ( SERVER1 => {tag => 53, ADMINS => undef, ADMINSGRP += undef}, SERVER2 => {tag => 1, ADMINS = "account1", ADMINSGRP = ["gl +obal1","global2"]}, SERVER3 => {tag => 1236 ADMINS = "account2", ADMI +NSGRP = ["global1","global2"]}, SERVER4 => {tag => 1236 ADMINS = "acc +ount1", ADMINSGRP = ["global1","global2"]} ) )


i wanna pick out values in {tag} and {admins} and group/sort my hash with them. so all in all. I wanna 1. sort by key alphabetically1 after that, 2. sort by value in {tag} (so it groups all the 1s together all the 87s together etc), 3. drop all the ..{tag}==53 to the bottom. and finally 4. do that pattern match mentioned above and further group my records with that.

foreach my $server ( sort {$my_server_hash {$a} cmp $my_server_hash +{$b} && $my_server_hash{$a}{tag} <=> $my_server_hash{$b} +{tag} } keys %my_server_hash) { my $member = $my_server_hash{$server}{ADMINS}; $servercount++; $access = $my_server_hash{$server}{tag}; if ($access == 1) { $comment = ""; $color="#99FF33"; } elsif ($member =~ s/$account/FOUND:$account/i && $acces +s !=1) { # this means password is wrong! $color = "#FF3366"; $comment = "<a name=\"password_wrong\"><b>$ +account password is wrong! </b></a>"; } elsif ($access == 53) { $comment = " <a name=\"unavailable\"> <font color + = \"white\"> <b>machine unavailable! <br></b></a> "; $color = "#996666"; } elsif($my_server_hash{$server}{ADMINS}) { $comment = " <a name=\"no_account\"><b> $ac +count account does not exist</b> </a>"; $color = "#FF3333"; } else { $comment = " <a name=\"unknown\"> <font co +lor = \"white\"> <b>unable to access! <br></b></a> "; $color = "#FF66CC"; } server_data_row("19%",$color, "27%", "Verdana, Arial, Helvetica, sa +ns-serif","4",$server,$htm_pass_handle); server_data_row("12%",$color, "27%", "Courier New, Courier, mono"," +2","$member",$htm_pass_handle); server_data_row("69%",$color, "27%", "Courier New, Courier, mono"," +3",$access."<b> $comment</b>",$htm_pass_handle,"</tr>"); } # foreach server


I think i have enough to go on i will probably go down the graff has suggested although i dont think i'm understanding the concept to implement it properly.

any further nudges in the right direction are very welcome.

for now back to my code. thanks again. C.

In reply to Re: hash sort problems by Conal
in thread hash sort problems by Conal

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.