Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

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



  • 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 sharing their wisdom with the Monastery: (7)
As of 2024-04-19 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found