I have this hash however I cannot for the life of me figure out how to apply sort to it. I have posted part of the hash but enough to make my point. I need to sort by the forth array value ie: $licensehash{CI}{CI_CTAG}[3]; Any ideas out there? Bonus: one line foreach loop.
our %licensehash = ( CI => { CI_CTAG => ['','',"", "Customer Name", 1, '[^0-9a-zA-Z\-]', [@ +new_license_versions]], CI_CID => ['','',"", "Chassis Serial", 1, '[^0-9a-zA-Z]', [@ne +w_license_versions]], CI_UID1 => ['','',"", "MAC 1/UUID", 0, '[^0-9a-zA-Z:-]', [$iTX +_2_7_VERSION, $iTX_SBB_VERSION_val]], CI_UID2 => ['','',"", "MAC 2", 0, '[^0-9a-zA-Z:-]', [$iTX_2_7_ +VERSION]], CI_SER => ['','',"", "Lenovo Serial", 0, '[^0-9a-zA-Z]', [$iTX +_Lenovo_VERSION_val]], CI_UUID => ['','',"", "Lenovo UUID", 0, '[^0-9a-zA-Z]', [$iTX_ +Lenovo_VERSION_val]], CI_E => ['','',"0", "Epoc", 0, '[^0-9]', [@new_license_version +s]], #0 unlicensed, 1 first license }, COM => { COM_PV => ['','',$iTX_SBB_VERSION_val, "iTX Version", 1, '[^0- +9.]', [@new_license_versions]], COM_MV => ['','',$VERSION, "LMU Version", 0, '[^0-9.]', [@new_ +license_versions]], COM_KT => ['','',"MASTER", "Key Type", 0, 'MASTER', [@new_lice +nse_versions]], COM_CD => ['','',sub{sprintf '%04d-%02d-%02d', $_[5]+1900, $_[ +4]+1, $_[3]}->(localtime), "Creation Date", 0, '[^0-9\-]', [@new_lice +nse_versions]], COM_USER => ['','',sub{qx"echo %username%"}, "Creation User", +0, '[^0-9a-zA-Z\-]', [@new_license_versions]], }, ISCSI => { ISCSI_T => ['','',"-1", "iSCSI", 1, "-1,89478485", [@new_licen +se_versions]], }, NAS => { NAS_T => ['','',"0", "NAS", 1, "-1,89478485", [$iTX_Lenovo_VER +SION_val, $iTX_2_7_VERSION]], }, RPL => { RPL_T => ['','',"-1", "Sync Replication", 1, "-1,89478485", [@ +new_license_versions]], }, ); #Help/fix me please foreach my $tag (keys %licensehash) { foreach my $type (keys %{$licensehash{$tag}}) { print "$licensehash{$tag}{$type}[3]: $licensehash{$tag}{$type} +[0]"; } }

In reply to sort hash by value by glenn

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.